php - Passing a parameter in Laravel Form Request -
i have admin able create , update users. made new form request called 'userupdaterequest'. how can pass user id can update user detail? here rules:
// userupdaterequest public function rules() { return [ 'firstname' => 'required|min:2|max:255', 'lastname' => 'required|min:2|max:255', 'username' => 'required|max:255', 'password' => 'required|min:6|confirmed', 'email' => 'required|email|max:255|unique:users,email,????', 'contact' => 'required|integer', 'gender' => 'required|in:m,f', 'role_id' => 'required|exists:roles,id', ]; } // controller public function update(userupdaterequest $request, user $user) { $user->update([ 'firstname' => request('firstname'), 'lastname' => request('lastname'), 'username' => request('username'), 'email' => request('email'), 'contact' => request('contact'), 'gender' => request('gender'), 'role_id' => request('role_id'), ]); session()->flash('message', 'user has been added.'); return redirect('/users/' . $user->id); }
'required|email|max:255|unique:users,email,????',
confused.
since admin changing users assume have user data on view file.
you can pass hidden input on form.
<input type="hidden" value="{{$user->id}}" name="user_id" />
and receive on controller.
$user_id = $request->input('user_id'); $user = \app\user::find($user_id); //validation comes here
edit depending on new information
public function update(userupdaterequest $request, user $user)
should
public function update(request $request, user $user)
and have call request on controller;
use illuminate\http\request;
after can request
dd($request->all());
but if using special request post userupdaterequest class.
Comments
Post a Comment