0
Look at your code, the method attachRole
expects an object and not a number.
public function attachRole() {
if(!$this->hasRole($role->name)) {
$this->roles()->attach($role);
}
}
The object must contain a property name
, see line 51 of the code (according to the image you entered in the perguta).
Therefore, the code $user->attachRole(12);
causes the error below to be triggered:
Trying to get Property 'name' of non-object
Translating, the code is trying to get the property name
of an element that is not an object.
The method $user->roles()
returns an object that provides the method attach
, so it works:
$user->roles()->attach(12);
Surely there is some validation within the method attach
which checks if the given value is an object, so no error is triggered, but this only by analyzing the code of the method.
I took a look at the Laravel Defender documentation and made some changes $user = $this->create($request->all()); $role = Defender::findRole('Admin'); $user->attachRole($role); now I get the following error "Class 'Illuminate Foundation Auth Defender' not found" I reviewed the entire installation and did according to the Documentation, there are no installation errors!!
– Gabriel Alves