按下提交按钮后,没有任何反应,也没有更新数据库。请帮助我。
控制器:
public function update(Request $request, $id)
{
$this->validate(request(), [
'name' => 'required',
'email' => 'required|email|unique:users',
]);
//$user = Auth::user();
$user = user::where('id',$id)->update($request->except('_token','_method'));
$user->name = request('name');
$user->email = request('email');
$user->password = bcrypt(request('password'));
$user->firstname = $request->firstname;
$user->middlename = $request->middlename;
$user->lastname = $request->lastname;
$user->birthday = $request->birthday;
$user->nationality = $request->nationality;
$user->gender = $request->gender;
$user->civilstatus = $request->name;
$user->mobilenum = $request->mobilenum;
$user->worknum = $request->worknun;
$user->workadd = $request->workadd;
$user->homeadd = $request->homeadd;
$user->email = $request->email;
$user->save();
return redirect(route('user.user.show'))->with('message','Announcement Updated Succesfully');;
}
edit.blade.php
<form method="POST" action="{{ route('user.user.update', $user->id)}}">
{{ csrf_field() }}
{{ method_field('PATCH') }}
..
..
..
<button type="submit" class="btn btn-primary">Submit</button>
<a href="{{ route('user.user.show', $user->id)}}" class="btn btn-warning">Back</a>
路线
Route::get('users/{user}', ['as' => 'user.user.show', 'uses' => 'UserController@index']);
Route::get('users/edit/{user}', ['as' => 'user.user.edit', 'uses' => 'UserController@edit']);
Route::PATCH('users/update/{users}', ['as' => 'user.user.update', 'uses' => 'UserController@update']);
请帮助我。预先谢谢你!
答案 0 :(得分:3)
据我所知,我认为您$request
未通过unique
上的email
验证。
由于它是一种更新功能,因此保留格式为(例如,电子邮件-用户名)的唯一字段不变,将导致验证错误,请尝试绕过此操作:
'email' => ['required','email',Rule::unique('users')->ignore($id)]