Skip to content

Commit 3e5734a

Browse files
authored
Merge pull request #23 from laravelcm/search
Search
2 parents 9145188 + 59a371c commit 3e5734a

File tree

27 files changed

+1093
-381
lines changed

27 files changed

+1093
-381
lines changed

app/Console/Kernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Console\Scheduling\Schedule;
66
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
use Spatie\SiteSearch\Commands\CrawlCommand;
78

89
class Kernel extends ConsoleKernel
910
{
@@ -29,6 +30,7 @@ protected function schedule(Schedule $schedule)
2930
$schedule->command('lcm:post-article-to-twitter')->twiceDaily(12, 16);
3031
$schedule->command('lcm:post-article-to-telegram')->twiceDaily(13, 17);
3132
$schedule->command('sitemap:generate')->daily();
33+
$schedule->command(CrawlCommand::class)->everyThreeHours();
3234
}
3335

3436
/**
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Http\Livewire\Modals;
4+
5+
use App\Models\Article;
6+
use App\Policies\ArticlePolicy;
7+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
8+
use LivewireUI\Modal\ModalComponent;
9+
10+
class DeleteArticle extends ModalComponent
11+
{
12+
use AuthorizesRequests;
13+
14+
public ?Article $article = null;
15+
16+
public function mount(int $id)
17+
{
18+
$this->article = Article::find($id);
19+
}
20+
21+
public static function modalMaxWidth(): string
22+
{
23+
return 'xl';
24+
}
25+
26+
public function delete()
27+
{
28+
$this->authorize(ArticlePolicy::DELETE, $this->article);
29+
30+
$this->article->delete();
31+
32+
session()->flash('status', 'La discussion a été supprimé avec tous ses commentaires.');
33+
34+
$this->redirectRoute('articles');
35+
}
36+
37+
public function render()
38+
{
39+
return view('livewire.modals.delete-article');
40+
}
41+
}

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: 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+
8+
class Articles extends SpotlightCommand
9+
{
10+
protected string $name = 'Articles';
11+
12+
protected string $description = 'aller à la page des articles';
13+
14+
protected array $synonyms = [
15+
'articles',
16+
'article',
17+
'post',
18+
'blog',
19+
'news',
20+
];
21+
22+
public function execute(Spotlight $spotlight)
23+
{
24+
$spotlight->redirectRoute('articles');
25+
}
26+
}

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

app/Spotlight/FAQs.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+
8+
class FAQs extends SpotlightCommand
9+
{
10+
protected string $name = 'FAQs';
11+
12+
protected string $description = 'aller à la page des questions';
13+
14+
protected array $synonyms = [
15+
'faq',
16+
'question',
17+
'foire',
18+
];
19+
20+
/**
21+
* When all dependencies have been resolved the execute method is called.
22+
* You can type-hint all resolved dependency you defined earlier.
23+
*/
24+
public function execute(Spotlight $spotlight)
25+
{
26+
$spotlight->redirectRoute('faq');
27+
}
28+
}

app/Spotlight/Forum.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+
8+
class Forum extends SpotlightCommand
9+
{
10+
protected string $name = 'Forum';
11+
12+
protected string $description = 'aller sur le forum';
13+
14+
protected array $synonyms = [
15+
'question',
16+
'thread',
17+
'sujet',
18+
'problème',
19+
'issue',
20+
];
21+
22+
public function execute(Spotlight $spotlight)
23+
{
24+
$spotlight->redirectRoute('forum.index');
25+
}
26+
}

app/Spotlight/Guides.php

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

app/Spotlight/Slack.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+
8+
class Slack extends SpotlightCommand
9+
{
10+
protected string $name = 'Slack';
11+
12+
protected string $description = 'rejoindre le Slack de Laravel Cameroun';
13+
14+
protected array $synonyms = [
15+
'community',
16+
'join',
17+
'telegram',
18+
'whatsapp',
19+
'social',
20+
];
21+
22+
public function execute(Spotlight $spotlight)
23+
{
24+
$spotlight->redirectRoute('slack');
25+
}
26+
}

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

0 commit comments

Comments
 (0)