Level 53
I'm assuming you are posting an array of IDs ?
If so: change this:
$user->roles()->sync([$request->input('role')]);
// update to this (remove the [ ]
$user->roles()->sync( $request->input('role') );
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello
I'm trying to update the user role using Vue.
So I made an API with the method update :
public function update(Request $request, $id)
{
$user = User::findOrFail($id);
$this->validate(request(), [
'name'=>'string',
'full_name'=>'string'
]);
$user->name = $request->name;
$user->full_name = $request->full_name;
$user->roles()->sync([$request->input('role')]);
$user->save();
session()->flash('Done','updated');
return response()->json('d',200);
}
And I'm getting this error :
"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into `role_user` (`role_id`, `user_id`, `0`) values (0, 1, 3))"
What Am I doing wrong?
@lostdreamer_nl I was sending empty role_id field thats why i got the error
thanks
Please or to participate in this conversation.