File tree Expand file tree Collapse file tree 5 files changed +31
-0
lines changed Expand file tree Collapse file tree 5 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace App \Listeners ;
6+
7+ use Illuminate \Notifications \Events \NotificationSent ;
8+
9+ final class PersistTweetId
10+ {
11+ public function handle (NotificationSent $ event ): void
12+ {
13+ $ event ->notification
14+ ->getArticle ()
15+ ->update ([
16+ 'tweet_id ' => $ event ->response ->id ,
17+ ]);
18+ }
19+ }
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ final class Article extends Model
3535 'original_url ' ,
3636 'slug ' ,
3737 'is_pinned ' ,
38+ 'tweet_id ' ,
3839 'submitted_at ' ,
3940 'approved_at ' ,
4041 'shared_at ' ,
Original file line number Diff line number Diff line change @@ -38,4 +38,9 @@ public function generateTweet()
3838
3939 return "{$ title } by {$ author }\n\n{$ url }" ;
4040 }
41+
42+ public function getArticle ()
43+ {
44+ return $ this ->article ;
45+ }
4146}
Original file line number Diff line number Diff line change 44
55use App \Events \ArticleWasApproved ;
66use App \Events \ReplyWasCreated ;
7+ use App \Listeners \PersistTweetId ;
78use App \Listeners \SendArticleApprovedNotification ;
89use App \Listeners \SendNewReplyNotification ;
10+ use Illuminate \Notifications \Events \NotificationSent ;
911use Illuminate \Foundation \Support \Providers \EventServiceProvider as ServiceProvider ;
1012
1113class EventServiceProvider extends ServiceProvider
@@ -22,5 +24,8 @@ class EventServiceProvider extends ServiceProvider
2224 ArticleWasApproved::class => [
2325 SendArticleApprovedNotification::class,
2426 ],
27+ NotificationSent::class => [
28+ PersistTweetId::class,
29+ ],
2530 ];
2631}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ class AddTwitterColumns extends Migration
99 public function up ()
1010 {
1111 Schema::table ('articles ' , function (Blueprint $ table ) {
12+ $ table ->unsignedBigInteger ('tweet_id ' )->after ('is_pinned ' )->nullable ();
1213 $ table ->dateTime ('shared_at ' )->after ('approved_at ' )->nullable ();
1314 });
1415
You can’t perform that action at this time.
0 commit comments