Undefined method routeNotificationFor() when using trait

88 views Asked by At

I'm using the Notifable trait from the docs in Laravel 10.

Notifications work fine when using the User model.

Using a different model I get this error in the logs:

production.ERROR: Call to undefined method App\Models\Contractor::routeNotificationFor() {"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method App\Models\Contractor::routeNotificationFor() at /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:67)

The Contractor model has:

use Illuminate\Notifications\Notifiable;

and 

use Notifiable;

on it as per the User model and docs linked above.. It also has an email field (not that I'm using atm).

Firing the notification:

# Usually using the relationship
#$contractor = $this->model->contractor;
$contractor = Contractor::find(1);

if ($contractor)
{
     $contractor->notify(new JobContractor($this->model));
}

get_class($contractor) at this point says it's a App\Models\Contractor class and $contractor is set. echo $contractor->email does output the address so it is an instantiated model instance.

What else can I check here? Checking the definition of the traits in VSCode they seem to check out.

My Contractor class use(s) Notifiable trait which use(s) RoutesNotifications which has a routeNotificationFor function in it.

Edit 1: To test it's not an issue with the Notification and Mailable I changed to the other method using the facade:

use Illuminate\Support\Facades\Notification;
if ($contractor)
{
    #$contractor->notify(new JobContractor($this->model));
    $user = User::find(1);
    Notification::send($user, new JobContractor($this->model));
}

That does work.

Edit 2: I too am using queues like this answered question. However this is the same queue. I have restarted Supervisor and the server.

0

There are 0 answers