To update a user I used a FormRequest named UserByAdminFormRequest like this :
public function rules()
{
switch ($this->method()) {
case 'GET':
case 'DELETE': {
//some Rules
}
case 'POST': {
//some Rules
}
case 'PUT':
$user_id = $this->get('user_id');
dd($this);
return [
'name' => 'required',
'email' => 'email|unique:users,email,' . $user_id . ',user_id',
'password' => 'min:4',
're-password' => 'required_unless:password,' . NULL . '|same:password',
];
case 'PATCH': {
//some Rules
}
default:
break;
}
As you can see email field should be unique but to ignore current user in this case, I need to her user_id value.
For that I used $this->get('user_id') but it return null value always.
I used that FormRequest like this in my controller :
public function update(UserByAdminFormRequest $request, \App\User $user)
{
//
}
And the url that I called by PUT method is (for example) :
http://api.zarsystem.dev/v1/dashboard/user/7
What can I do in this case Or is there any alternate ways?