I register an observer in the boot method of AppServiceProvider.
Then I listen with Queue::after when a certain job has been finished.
The problem is that when I create the ProjectUserAssignments in the foreach loop the observer is not triggered! But they are correctly made within the database.
It looks like this:
ProjectUserAssignment::observe(ProjectUserAssignmentObserver::class);
Queue::after(function(JobProcessed $event) {
//When a project is created, create the employees and send to harvest.
if($event->job->resolveName() == HarvestProjectCreate::class) {
\Log::debug('start!');
$project = Project::latest()->first();
foreach($project->team->employees as $employee) {
ProjectUserAssignment::create([
'project_id' => $project->id,
'user_id' => $employee->id,
'is_project_manager' => false
]);
}
}
});
When I individually make 1 ProjectUserAssignment the observer is triggered! What could be going on here?