-
app/Notifications/ArticleApprovedNotification.php
Open in GitHubuse App\Mail\ArticleApprovedEmail; use App\Models\Article; use App\Models\User; use Illuminate\Notifications\Notification; final class ArticleApprovedNotification extends Notification { public $article; public function __construct(Article $article) { $this->article = $article; } public function via(User $user) { return ['mail', 'database']; } public function toMail(User $user) { return (new ArticleApprovedEmail($this->article)) ->to($user->emailAddress(), $user->name()); } public function toDatabase(User $user) { return [ 'type' => 'article_approved', 'article_title' => $this->article->title(), 'article_slug' => $this->article->slug(), ]; } }
-
app/Listeners/SendArticleApprovedNotification.php
Open in GitHubuse App\Events\ArticleWasApproved; use App\Notifications\ArticleApprovedNotification; final class SendArticleApprovedNotification { public function handle(ArticleWasApproved $event): void { $event->article->author()->notify(new ArticleApprovedNotification($event->article)); } }