Closed moonvader closed 2 years ago
Voyager uses destroy
to delete multiple model instances at once.
This doesn't trigger the deleted
event because the actual model is not retreived before.
But Voyager fires BreadDataDeleted
Thank you, in this case I need to add my custom listener? how can I access deleted user's id from it?
Add this into service provider e.g EventServiceProvider Event::listen(\TCG\Voyager\Events\BreadDataDeleted::class, CustomDeleteListener::class);
Then create a listener class
<?php
use TCG\Voyager\Events\BreadDataDeleted;
class CustomDeleteListener
{
/**
* Handle the event.
*
* @param BreadDataDeleted $event
* @return void
*/
public function handle(BreadDataDeleted $event)
{
if (!empty($event->dataType)) {
switch ($event->dataType->slug) {
case 'users':
$request = app(Request::class);
// custom logic
break;
}
}
}
}
More info on events: https://laravel.com/docs/8.x/events
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Laravel version
6.17
PHP version
7.4
Voyager version
1.5.2
Database
MySQL
Description
In User model I want to run custom actions when user is deleted so I add this events using code below
When I delete user from Voyager this actions are not being called. What am I doing wrong and are the any other way to run custom action when user is deleted from voyager admin panel?
Steps to reproduce
Delete user from Voyager admin panel
Expected behavior
deleted or deleting events are called
Screenshots
No response
Additional context
No response