Level 58
To notify assignees with a deleted post without any errors, you need to make a few changes to your code.
- In your
deletemethod in the Livewire component, you are passing the$postparameter to thePostDeletedevent constructor. However, in the event, you are using$this->postinstead of$post. Update yourdeletemethod as follows:
public function delete(Post $post)
{
abort_if(Gate::denies('post_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$post->delete();
event(new PostDeleted($post));
}
- In your
PostDeletedEmaillistener, you are using theobjecttype hint for the$eventparameter. Instead, you should type hint it asPostDeletedevent. Update yourhandlemethod as follows:
public function handle(PostDeleted $event): void
{
$post = $event->post;
$project = $post->project;
$assignees = $project->assignees()->get();
Notification::send(
$assignees,
new PostDeletedNotification($post)
);
}
- In your
PostDeletedNotificationclass, you are missing the$postproperty declaration. Add the following line at the top of the class:
protected $post;
With these changes, the assignees will be notified with a deleted post without any errors.