-
app/Notifications/QuestionAnswered.php
Open in GitHubuse App\Models\Question; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; final class QuestionAnswered extends Notification { use Queueable; public function __construct(private Question $question) {} public function via(object $notifiable): array { return ['database']; } public function toDatabase(object $notifiable): array { return [ 'question_id' => $this->question->id, ]; } }
-
app/Observers/QuestionObserver.php
Open in GitHubuse App\Models\Question; use App\Notifications\QuestionCreated; use App\Notifications\UserMentioned; final readonly class QuestionObserver { // ... public function updated(Question $question): void { // ... $question->from->notify(new QuestionAnswered($question)); $question->mentions()->each->notify(new UserMentioned($question)); } // ... }