I am working on a larval project that has two event when a user is registered one event will great all the roles and permissions for the user and the other will send a welcome email to the user. In the event service provider I have this
protected $listen = [
'App\Events\NewUser' => [
'App\Listeners\CreateAuthorization',
'App\Listeners\SendWelcomeEmail',
],
];
In the new user event I have the user being passed in the constructor like below.
class NewUser
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
public function __construct(User $user)
{
//
$this->user = $user;
}
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
I have only tired implementing one listener so far and that is the create authorization listener
class CreateAuthorization
{
public function __construct()
{
//
}
public function handle(NewUser $event)
{
//
Log::info('This is some useful information.');
$user_role = new UserRole();
$user_role->user_id = $event->user->id;
$user_role->permission_id = $role->id;
$user_role->save();
}
}
In the model class of the user I have this to link the event together.
protected $events = [
'created' => NewUser::class
];
I have tried clearing my cache and logging messages but I from what I see log messages are not even showing up which leads me to think that the event is not even being fired when I user is created. I am super lost on how to solve this issue.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire