Skip to content

Commit df2392b

Browse files
committed
ArticleWasCreated event
1 parent 010ba0f commit df2392b

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

app/Events/ArticleWasCreated.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use App\Models\Article;
6+
use Illuminate\Queue\SerializesModels;
7+
8+
class ArticleWasCreated
9+
{
10+
use SerializesModels;
11+
12+
public $article;
13+
14+
public function __construct(Article $article)
15+
{
16+
$this->article = $article;
17+
}
18+
}

app/Jobs/CreateArticle.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace App\Jobs;
44

5+
use App\Events\ArticleWasCreated;
56
use App\Http\Requests\ArticleRequest;
67
use App\Models\Article;
78
use App\Models\User;
8-
use App\Notifications\ArticleSubmitted;
9-
use Illuminate\Notifications\AnonymousNotifiable;
109
use Illuminate\Support\Facades\App;
1110

1211
final class CreateArticle
@@ -60,7 +59,7 @@ public function handle(): Article
6059
$article->syncTags($this->tags);
6160

6261
if (App::environment() !== 'testing') {
63-
(new AnonymousNotifiable())->notify(new ArticleSubmitted($article));
62+
event(new ArticleWasCreated($article));
6463
}
6564

6665
return $article;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use App\Events\ArticleWasCreated;
6+
use App\Notifications\ArticleSubmitted;
7+
use Illuminate\Notifications\AnonymousNotifiable;
8+
9+
final class SendTelegramNewArticleNotification
10+
{
11+
public function handle(ArticleWasCreated $event): void
12+
{
13+
(new AnonymousNotifiable())->notify(new ArticleSubmitted($event->article));
14+
}
15+
}

app/Providers/EventServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
namespace App\Providers;
44

55
use App\Events\ArticleWasApproved;
6+
use App\Events\ArticleWasCreated;
67
use App\Events\ReplyWasCreated;
78
use App\Listeners\SendArticleApprovedNotification;
89
use App\Listeners\SendNewReplyNotification;
10+
use App\Listeners\SendTelegramNewArticleNotification;
911
use App\Listeners\StoreTweetIdentifier;
1012
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
1113
use Illuminate\Notifications\Events\NotificationSent;
@@ -21,6 +23,9 @@ class EventServiceProvider extends ServiceProvider
2123
ReplyWasCreated::class => [
2224
SendNewReplyNotification::class,
2325
],
26+
ArticleWasCreated::class => [
27+
SendTelegramNewArticleNotification::class,
28+
],
2429
ArticleWasApproved::class => [
2530
SendArticleApprovedNotification::class,
2631
],

0 commit comments

Comments
 (0)