During assigning roles in laravel by using entrust i am getting error
Method Illuminate\Database\Eloquent\Collection::getKey does not exist. My code is :
$record = new User();
$data = $request->all();
$record->fill($data);
$record->save();
$roles = [1, 3]
$role = Role::whereIn('id', $roles)->get();
$record->attachRole($role);
record
here.? - Kamlesh Paul1
and3
but you are not doing anything with them? What is$record
and what is$role
? - Remul$role
is currently a collection of roles, did you try attaching only one role e.g.:$record->attachRole(1)
, it is unclear from the documentation if you can pass multiple roles toattachRole
- Remul