-2
According to Exception, the instant you try to grab the property $user->id
, the variable $user
is not an object. Actually, this variable is null.
This is because you are assigning to the variable $user
the return of function attach
, which is of the void type:
$user = (...)->attach($permissao->id);
To fix the problem, just fragment your code into two parts:
$user = User::create([
'nome' => $request->nome,
'email' => $request->email,
'password' => bcrypt($request->password)
]);
$user->roles()->attach($permissao->id);
// Continua o código normalmente...
Your example could be written to make life easier for those who are visiting the site to consult the question and to answer you as well. Give a read on these rules here: https://pt.meta.stackoverflow.com/questions/1186/como-crea-example-m%C3%adnimo-completo-e-verific%C3%a1vel? cb=1.
– Gabriel Faria