Does your notification class implements the Illuminate\Contracts\Queue\ShouldQueue interface and also uses the Illuminate\Bus\Queueable trait?
Documentation: https://laravel.com/docs/5.6/notifications#queueing-notifications
On some events and notifications that implement the ShouldQueueinterface, I receive the following error when triggering the actions via the browser (everything works via console when executing tests):
Call to undefined relationship [pivot] on model [App\Models\User].
As soon as I remove the interface declaration, everything works. But, I would really like to queue the notifications and events.
The error is caused by this relation on a model App\Models\Organizer:
public function members() {
return $this->belongsToMany(User::class,'organizer_members', 'organizer_id', 'user_id')
->using(OrganizerMember::class)
->withPivot('role_id', 'accepted')
->withTimestamps();
}
When I modify the relation by adding a ->as('membership'), I receive the following error:
Call to undefined relationship [membership] on model [App\Models\User].
So, this should be the error causing relation.
I guess the error occurs on every event or notification that implements the ShouldQueue interface and manages a variable with a relation to the App\Models\Organizer model.
Is this a Laravel bug or am I doing something wrong? I'm using Laravel v5.6.23.
Yes you are right. So, I couldn't reproduce the error on a fresh installation of Laravel. I guess my project is already just too big with too complex relationship definitions that causes the error. So, one event the error occurred is when I try to attach a member to an organizer and send a notification on a queue with the organizer as a parameter:
$organizer->members()->attach($user);
$user->notify(new OrganizerMemberInvitedNotification($organizer));
I noticed that when I load a fresh copy of the organizer from the database, everything works fine:
$organizer->members()->attach($user);
$user->notify(new OrganizerMemberInvitedNotification($organizer->fresh()));
So, I guess the problem is related to the loaded members relationship on the Organizer model, but I don't know if this is an issue with the Laravel framework or an error in my code.
But, I'm fine with just loading a fresh copy of the organizer from the database to solve this issue! :)
Please or to participate in this conversation.