Missing required parameter for [Route: blog.update] [URI: blog/{post}/update] [Missing parameter: post].
in routes :
Route::put('/blog/{post}/update', [BlogController::class, 'update'])->name('blog.update');
in BlogController :
`
public function update(Request $request,Post $post){
$request->validate([
'title' => 'required',
'image' => 'required | image',
'body' => 'required'
]);
$postId = $post->id;
$title = $request->input('title');
$slug = Str::slug($title,'-').'-'.$postId;
// $user_id = Auth::user()->id;
$body = $request->input('body');
//File upload
$imagePath = 'storage/'. $request->file('image')->store('postImages','public');
// $post = new Post();
$post->title = $title;
$post->slug = $slug;
// $post->user_id = $user_id;
$post->body = $body;
$post->imagePath = $imagePath;
$post->save();
return redirect()->back()->with('status', 'Post edited successfully');
dd('validation passed . You can request the input');
}
`
Please solve this issue
I want to update the post
2
Answers
If you are using the
route()
helper in your form. You can pass the parameter using it :which is the
post
is the parameter you name in the route.Since you haven’t posted your blade file so here’s the full method:
in your route:
in your blade form make tag like this:
Then in your controller update function handle the
request
and$id
like this: