Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

laravelio/laravel.io

2497 stars
2 code files
View laravelio/laravel.io on GitHub

app/Notifications/ArticleApprovedNotification.php

Open in GitHub
use 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 GitHub
use App\Events\ArticleWasApproved;
use App\Notifications\ArticleApprovedNotification;
 
final class SendArticleApprovedNotification
{
public function handle(ArticleWasApproved $event): void
{
$event->article->author()->notify(new ArticleApprovedNotification($event->article));
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.