【发布时间】:2021-11-06 16:48:09
【问题描述】:
我想用新的控制器名称 StaffController 编辑帖子,但出现错误 Missing required parameter for Route
缺少 [Route: verify.update] [URI: verify/{verification}] [缺少参数:verification]。
控制器
public function edit(Request $request, Post $post)
{
$choices = Choice::all();
$pets = Pet::all();
$types = Type::all();
$vehicles = Vehicle::all();
$genders = Gender::all();
$reasons = Reason::all();
$posts = Post::all();
return view('dashboard.staff.edit',compact('post', 'types', 'vehicles', 'pets', 'choices', 'genders', 'reasons'));
}
public function update(Request $request, Post $post)
{
$request->validate([
'phonenumber' => 'required',
]);
$input = $request->all();
if ($image = $request->file('image')) {
$destinationPath = 'image/';
$profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
$image->move($destinationPath, $profileImage);
$input['image'] = "$profileImage";
}else{
unset($input['image']);
}
$post->update($input);
return back()->with('success', 'Post verification successfully.');
}
public function destroy(Post $post, $id)
{
$this->authorize('isStaff');
$post = Post::find($id);
$post->delete();
return back()->with('success','Post deleted successfully');
}
路线
Route::resource('verification', StaffController::class);
查看
<form action="{{ route('verification.update', ['verification'=>$post->id]) }}" x-data="{types: {{$post->type_id}}}" method="POST" enctype="multipart/form-data">
@csrf
@method('PUT')
【问题讨论】:
-
您在控制器中请求
Post对象的操作中发送id。也许在更新函数中删除$post的类型
标签: laravel