我正在尝试更新我的用户个人资料,但遇到了问题Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException 此路由不支持 PUT 方法。支持的方法:GET、HEAD、POST。我已经定义了路线,但我不确定为什么会发生这种情况。web.phpRoute::get('/user/{id}',[UserController::class,'show'])->name('user.profile');Route::get('/edit/user/',[UserController::class,'edit'])->name('user.edit');Route::post('/edit/user/',[UserController::class,'update'])->name('user.update');UserControllerpublic function update(Request $request) { $user = User::find(Auth::user()->id); if ($user){ $validate = null; if (Auth::user()->email === $request ['email']) { $validate = $request->validate([ 'name' => 'required', 'email' => 'required', 'phone' => 'required', 'address' => 'required' ]); } else { $validate = $request->validate([ 'name' => 'required', 'email' => 'required', 'phone' => 'required', 'address' => 'required' ]); } if($validate){ $user->name = $request['name']; $user->email =$request['email']; $user->phone = $request['phone']; $user->address = $request['address']; $user->save(); $request ->session->flash('success', 'Profile have been updated'); return redirect()->back(); } else{ return redirect()->back(); } } else { return redirect()->back(); } }edit.blade.php<form class="form-horizontal" action="{{route('user.update',$user->id)}}" method="POST"> @csrf @method('PUT') @if(session('success')) <div class="alert alert-success" role="alert"> {{session('success')}} </div>
1 回答
HUWWW
TA贡献1874条经验 获得超12个赞
从刀片文件中删除@method('PUT') -
<form class="form-horizontal" action="{{route('user.update',$user->id)}}" method="POST">
@csrf
@if(session('success'))
<div class="alert alert-success" role="alert">
{{session('success')}}
</div>
@endif
<div class="card-body">
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="name" value="{{$user->name}}">
</div>
</div>
- 1 回答
- 0 关注
- 87 浏览
添加回答
举报
0/150
提交
取消