LARAVEL-提交表单时未更新数据库
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LARAVEL-提交表单时未更新数据库相关的知识,希望对你有一定的参考价值。
按下提交按钮时,没有任何反应,也没有更新数据库。请帮助我。
控制器:
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']);
请帮助我。预先谢谢!
答案
[据我所知,我认为您是$request
未通过unique
上的email
验证。
因为这是一个更新函数,将唯一字段保留为格式为[[(例如,电子邮件-用户名),将导致验证错误,请尝试绕过此操作:
'email' => ['required','email',Rule::unique('users')->ignore($id)]
以上是关于LARAVEL-提交表单时未更新数据库的主要内容,如果未能解决你的问题,请参考以下文章