Skip to content

Commit d13039a

Browse files
committed
✨ mis en place de la recherche
1 parent 0d0b888 commit d13039a

File tree

25 files changed

+1040
-1085
lines changed

25 files changed

+1040
-1085
lines changed

app/Spotlight/Article.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Spotlight;
4+
5+
use App\Models\Article as ArticleModel;
6+
use LivewireUI\Spotlight\Spotlight;
7+
use LivewireUI\Spotlight\SpotlightCommand;
8+
use LivewireUI\Spotlight\SpotlightCommandDependencies;
9+
use LivewireUI\Spotlight\SpotlightCommandDependency;
10+
use LivewireUI\Spotlight\SpotlightSearchResult;
11+
12+
class Article extends SpotlightCommand
13+
{
14+
protected string $name = 'Article';
15+
16+
protected string $description = 'rechercher un article spécifique';
17+
18+
protected array $synonyms = [];
19+
20+
public function dependencies(): ?SpotlightCommandDependencies
21+
{
22+
return SpotlightCommandDependencies::collection()
23+
->add(
24+
SpotlightCommandDependency::make('article')
25+
->setPlaceholder('Rechercher un article spécifique')
26+
);
27+
}
28+
29+
public function searchArticle($query)
30+
{
31+
return ArticleModel::published()->where('title', 'like', "%$query%")
32+
->get()
33+
->map(function(ArticleModel $article) {
34+
return new SpotlightSearchResult(
35+
$article->slug(),
36+
$article->title,
37+
sprintf('par @%s', $article->author->username)
38+
);
39+
});
40+
}
41+
42+
public function execute(Spotlight $spotlight, ArticleModel $article)
43+
{
44+
$spotlight->redirectRoute('articles.show', $article);
45+
}
46+
}

app/Spotlight/Articles.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Spotlight;
4+
5+
use LivewireUI\Spotlight\Spotlight;
6+
use LivewireUI\Spotlight\SpotlightCommand;
7+
use LivewireUI\Spotlight\SpotlightCommandDependencies;
8+
use LivewireUI\Spotlight\SpotlightCommandDependency;
9+
use LivewireUI\Spotlight\SpotlightSearchResult;
10+
11+
class Articles extends SpotlightCommand
12+
{
13+
protected string $name = 'Articles';
14+
15+
protected string $description = 'aller à la page des articles';
16+
17+
protected array $synonyms = [
18+
'articles',
19+
'article',
20+
'post',
21+
'blog',
22+
'news',
23+
];
24+
25+
public function execute(Spotlight $spotlight)
26+
{
27+
$spotlight->redirectRoute('articles');
28+
}
29+
}

app/Spotlight/Discussion.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Spotlight;
4+
5+
use App\Models\Discussion as DiscussionModel;
6+
use LivewireUI\Spotlight\Spotlight;
7+
use LivewireUI\Spotlight\SpotlightCommand;
8+
use LivewireUI\Spotlight\SpotlightCommandDependencies;
9+
use LivewireUI\Spotlight\SpotlightCommandDependency;
10+
use LivewireUI\Spotlight\SpotlightSearchResult;
11+
12+
class Discussion extends SpotlightCommand
13+
{
14+
protected string $name = 'Discussion';
15+
16+
protected string $description = 'rechercher une discussion spécifique';
17+
18+
protected array $synonyms = [];
19+
20+
public function dependencies(): ?SpotlightCommandDependencies
21+
{
22+
return SpotlightCommandDependencies::collection()
23+
->add(
24+
SpotlightCommandDependency::make('discussion')
25+
->setPlaceholder('Rechercher une discussion spécifique')
26+
);
27+
}
28+
29+
public function searchDiscussion($query)
30+
{
31+
return DiscussionModel::where('title', 'like', "%$query%")
32+
->get()
33+
->map(function(DiscussionModel $discussion) {
34+
return new SpotlightSearchResult(
35+
$discussion->slug(),
36+
$discussion->title,
37+
sprintf('par @%s', $discussion->author->username)
38+
);
39+
});
40+
}
41+
42+
public function execute(Spotlight $spotlight, DiscussionModel $discussion)
43+
{
44+
$spotlight->redirectRoute('discussions.show', $discussion);
45+
}
46+
}

app/Spotlight/Discussions.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Spotlight;
4+
5+
use LivewireUI\Spotlight\Spotlight;
6+
use LivewireUI\Spotlight\SpotlightCommand;
7+
use LivewireUI\Spotlight\SpotlightCommandDependencies;
8+
use LivewireUI\Spotlight\SpotlightCommandDependency;
9+
use LivewireUI\Spotlight\SpotlightSearchResult;
10+
11+
class Discussions extends SpotlightCommand
12+
{
13+
protected string $name = 'Discussions';
14+
15+
protected string $description = 'aller à la page des discussions';
16+
17+
protected array $synonyms = [
18+
'débat',
19+
'conversation'
20+
];
21+
22+
public function execute(Spotlight $spotlight)
23+
{
24+
$spotlight->redirectRoute('discussions.index');
25+
}
26+
}

app/Spotlight/FAQs.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Spotlight;
4+
5+
use LivewireUI\Spotlight\Spotlight;
6+
use LivewireUI\Spotlight\SpotlightCommand;
7+
use LivewireUI\Spotlight\SpotlightCommandDependencies;
8+
use LivewireUI\Spotlight\SpotlightCommandDependency;
9+
use LivewireUI\Spotlight\SpotlightSearchResult;
10+
11+
class FAQs extends SpotlightCommand
12+
{
13+
protected string $name = 'FAQs';
14+
15+
protected string $description = 'aller à la page des questions';
16+
17+
protected array $synonyms = [
18+
'faq',
19+
'question',
20+
'foire'
21+
];
22+
23+
/**
24+
* When all dependencies have been resolved the execute method is called.
25+
* You can type-hint all resolved dependency you defined earlier.
26+
*/
27+
public function execute(Spotlight $spotlight)
28+
{
29+
$spotlight->redirectRoute('faq');
30+
}
31+
}

app/Spotlight/Forum.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Spotlight;
4+
5+
use LivewireUI\Spotlight\Spotlight;
6+
use LivewireUI\Spotlight\SpotlightCommand;
7+
use LivewireUI\Spotlight\SpotlightCommandDependencies;
8+
use LivewireUI\Spotlight\SpotlightCommandDependency;
9+
use LivewireUI\Spotlight\SpotlightSearchResult;
10+
11+
class Forum extends SpotlightCommand
12+
{
13+
protected string $name = 'Forum';
14+
15+
protected string $description = 'aller sur le forum';
16+
17+
protected array $synonyms = [
18+
'question',
19+
'thread',
20+
'sujet',
21+
'problème',
22+
'issue',
23+
];
24+
25+
public function execute(Spotlight $spotlight)
26+
{
27+
$spotlight->redirectRoute('forum.index');
28+
}
29+
}

app/Spotlight/Guides.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Spotlight;
4+
5+
use LivewireUI\Spotlight\Spotlight;
6+
use LivewireUI\Spotlight\SpotlightCommand;
7+
use LivewireUI\Spotlight\SpotlightCommandDependencies;
8+
use LivewireUI\Spotlight\SpotlightCommandDependency;
9+
use LivewireUI\Spotlight\SpotlightSearchResult;
10+
11+
class Guides extends SpotlightCommand
12+
{
13+
protected string $name = 'Guides';
14+
15+
protected string $description = 'aller à la page du code de conduite';
16+
17+
protected array $synonyms = [
18+
'code',
19+
'conduite',
20+
'règles',
21+
'comportement',
22+
];
23+
24+
public function execute(Spotlight $spotlight)
25+
{
26+
$spotlight->redirectRoute('rules');
27+
}
28+
}

app/Spotlight/Slack.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Spotlight;
4+
5+
use LivewireUI\Spotlight\Spotlight;
6+
use LivewireUI\Spotlight\SpotlightCommand;
7+
use LivewireUI\Spotlight\SpotlightCommandDependencies;
8+
use LivewireUI\Spotlight\SpotlightCommandDependency;
9+
use LivewireUI\Spotlight\SpotlightSearchResult;
10+
11+
class Slack extends SpotlightCommand
12+
{
13+
protected string $name = 'Slack';
14+
15+
protected string $description = 'rejoindre le Slack de Laravel Cameroun';
16+
17+
protected array $synonyms = [
18+
'community',
19+
'join',
20+
'telegram',
21+
'whatsapp',
22+
'social',
23+
];
24+
25+
public function execute(Spotlight $spotlight)
26+
{
27+
$spotlight->redirectRoute('slack');
28+
}
29+
}

app/Spotlight/Sujet.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace App\Spotlight;
4+
5+
use App\Models\Thread;
6+
use LivewireUI\Spotlight\Spotlight;
7+
use LivewireUI\Spotlight\SpotlightCommand;
8+
use LivewireUI\Spotlight\SpotlightCommandDependencies;
9+
use LivewireUI\Spotlight\SpotlightCommandDependency;
10+
use LivewireUI\Spotlight\SpotlightSearchResult;
11+
12+
class Sujet extends SpotlightCommand
13+
{
14+
protected string $name = 'Sujet';
15+
16+
protected string $description = 'Rechercher un sujet dans le forum';
17+
18+
protected array $synonyms = [
19+
'topic',
20+
'sujet',
21+
'forum',
22+
'thread',
23+
];
24+
25+
public function dependencies(): ?SpotlightCommandDependencies
26+
{
27+
return SpotlightCommandDependencies::collection()
28+
->add(
29+
SpotlightCommandDependency::make('thread')
30+
->setPlaceholder('Rechercher un sujet dans le forum')
31+
);
32+
}
33+
34+
public function searchThread($query)
35+
{
36+
return Thread::where('title', 'like', "%$query%")
37+
->get()
38+
->map(function(Thread $thread) {
39+
// You must map your search result into SpotlightSearchResult objects
40+
return new SpotlightSearchResult(
41+
$thread->slug(),
42+
$thread->name,
43+
sprintf('par @%s', $thread->author->username)
44+
);
45+
});
46+
}
47+
48+
public function execute(Spotlight $spotlight, Thread $thread)
49+
{
50+
$spotlight->redirectRoute('forum.show', $thread);
51+
}
52+
}

app/Spotlight/Telegram.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App\Spotlight;
4+
5+
use LivewireUI\Spotlight\Spotlight;
6+
use LivewireUI\Spotlight\SpotlightCommand;
7+
use LivewireUI\Spotlight\SpotlightCommandDependencies;
8+
use LivewireUI\Spotlight\SpotlightCommandDependency;
9+
use LivewireUI\Spotlight\SpotlightSearchResult;
10+
11+
class Telegram extends SpotlightCommand
12+
{
13+
protected string $name = 'Telegram';
14+
15+
/**
16+
* This is the description of your command which will be shown besides the command name.
17+
*/
18+
protected string $description = 'rejoindre le groupe sur Telegram';
19+
20+
/**
21+
* You can define any number of additional search terms (also known as synonyms)
22+
* to be used when searching for this command.
23+
*/
24+
protected array $synonyms = [
25+
'channels',
26+
'social',
27+
'slack',
28+
'whatsapp',
29+
'community',
30+
];
31+
32+
public function execute(Spotlight $spotlight)
33+
{
34+
$spotlight->redirectRoute('telegram');
35+
}
36+
}

0 commit comments

Comments
 (0)