J
J
jazzus2019-04-09 00:09:30
Laravel
jazzus, 2019-04-09 00:09:30

Why is Call to a member function roles() on null?

Did the code
Auth::user()->roles()->attach(Role::ID__CUSTOMER);
return in the logs where could it find null there? Authorized user. The relation manytomany to roles is used everywhere, the role with the specified id exists. What can be checked?
Call to a member function roles() on null

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2019-04-09
@jazzus

The response from the service is not an authorized user.
So

$user = User::find($user_id);
$user->roles()->attach(Role::ID__CUSTOMER);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question