Skip to content

Commit cecb855

Browse files
committed
Store tweet id
1 parent 036a320 commit cecb855

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

app/Listeners/PersistTweetId.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

app/Models/Article.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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',

app/Notifications/PostArticleToTwitter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

app/Providers/EventServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use App\Events\ArticleWasApproved;
66
use App\Events\ReplyWasCreated;
7+
use App\Listeners\PersistTweetId;
78
use App\Listeners\SendArticleApprovedNotification;
89
use App\Listeners\SendNewReplyNotification;
10+
use Illuminate\Notifications\Events\NotificationSent;
911
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
1012

1113
class 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
}

database/migrations/2020_07_16_185353_add_twitter_columns.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)