-
app/Notifications/Item/ItemUpdatedNotification.php
Open in GitHubuse App\Models\Item; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; class ItemUpdatedNotification extends Notification implements ShouldQueue { use Queueable; public function __construct(public Item $item) { } public function via($notifiable) { return ['mail']; } public function toMail($notifiable) { return (new MailMessage) ->subject('Item ' . $this->item->title . ' has new updates') ->markdown('emails.item.updated', [ 'user' => $notifiable, 'item' => $this->item, 'activities' => $this->item->activities()->latest()->limit(2)->get() ]); } }
-
app/Observers/ItemObserver.php
Open in GitHubuse App\Models\Item; use App\Models\User; use App\Notifications\Item\ItemUpdatedNotification; class ItemObserver { // public function updating(Item $item) { // if ($isDirty) { $users = $item->subscribedVotes()->with('user')->get()->pluck('user'); $users->each(function (User $user) use ($item) { $user->notify(new ItemUpdatedNotification($item)); }); } } // }