@laksh again the update route, as defined, needs a Post ID, but you are not passing a Post ID to the route helper method. I don't understand the intent of your form - you have an empty textarea and are iterating over all Posts to display a date type form input??? What are you trying to achieve here?
This would be a typical Edit/Update flow - where the subject Post is a single Post!
Route::get('post/edit/{post}', [App\Http\Controllers\PostController::class, 'edit']);
Route::put('post/update/{post}', [App\Http\Controllers\PostController::class, 'update'])->name('update');
public function edit(post $post)
{
return view('posts.edit', compact('post'));
}
public function update(post $post, Request $request){
$request->validate([
'tittle' => 'required',
'body' => 'required'
]);
$post->tittle = $request->tittle;
$post->body = $request->body;
$post->save();
return redirect('/home')->with('success', 'post updated successfully');
}
<form action="{{ route('update', $post) }}" method="post">
@csrf
@method('PUT')
<div class="form-group">
<label for="">Post Tittle</label>
<input type="text" name="tittle" class="form-control">
</div>
<div class="form-group">
<label for="">Post Body</label>
<textarea name="body" id="" cols="30" rows="10" class="form-control" >{{ $post->body }}</textarea>
</div>
<div class="form-group">
<label for="">Publish At</label>
<input type="date" name="published_at" class="form-control" value="{{ date('y-m-d', strtotime($post->published_at)) }}">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>