0
votes

I faced issue in Laravel 5.7

Error as follows

Method Illuminate\Database\Query\Builder::routeNotificationFor does not exist.

My code as follows

$users = User::find(1);
Notification::send($users, new UserActivity());

Users return value as follows

{"id":1, "name":"First Name", "email":"[email protected]","mobile":"9999999999","reset_password":0,"avatar":null,"created_at":"2019-04-11 10:39:08","updated_at":"2019-04-11 10:39:08","deleted_at":null}

This is working fine with Auth user as follows

Notification::send(Auth()->user(), new UserActivity());

If anyone faced the same issue ?

1
Have you checked what does your $users returns? Before you send notification try dumping the $users like this: dd($users); And make sure that it returns a App\User instance .nakov
$users returns are correctElby
you showed a json object being returned when using User::find(1) is that what you get by using dd or you print the result by returning the user return $users?nakov
It is i write to the Log fileElby

1 Answers

0
votes

Problem solved from the hint @nakov

Have to add Illuminate\Notifications\Notifiable trait in User model.