Laravel 10: Problems with Event Listeners Not Firing on Model Events After Factory Seeding
Does anyone know how to I've been struggling with this for a few days now and could really use some help. Hey everyone, I'm running into an issue that's driving me crazy. I'm working on a personal project and I'm working with an scenario where my event listeners are not firing when I trigger model events after seeding my database with factories. I have a `User` model with an event listener set up for the `created` event. Here's how I defined the listener in my `EventServiceProvider`: ```php protected $listen = [ UserCreated::class => [ SendWelcomeEmail::class, ], ]; ``` I also have the model set up to dispatch the event: ```php class User extends Model { protected $dispatchesEvents = [ 'created' => UserCreated::class, ]; } ``` However, when I run my factory to seed data in my database like this: ```php User::factory()->count(50)->create(); ``` I expected the `SendWelcomeEmail` listener to be triggered for each new user created, but nothing happens. I've tried using `dispatchNow` for the event, and even manually firing the event after creating a user, like this: ```php foreach (User::factory()->count(50)->make() as $user) { $user->save(); event(new UserCreated($user)); } ``` But I still do not see any emails being sent. I've checked the log files, and there are no errors indicating that the event was not dispatched. My listener is properly set up to handle the event, but I suspect that the scenario might be related to how Laravel handles model events during the factory seeding process. Is there something I'm missing here? Any insights or suggestions would be greatly appreciated! What am I doing wrong? I recently upgraded to Php latest. What would be the recommended way to handle this?