Controllers/HomeController.php
public function edit(Task $task)
{
return view('edit', compact('task'));
}
public function update(Request $request, Task $task)
{
$request->validate(['title' => 'required|min:3', 'description' => 'required', ]);
$task->title = $request->title;
$task->description = $request->description;
$task->save();
$request->session()
->flash('message', 'Successfully modified the task!');
return redirect('viewalltask');
}
routes/web.php
Route::post('/{task}/', 'HomeController@update')->name('update');
views/edit.blade.php
<form action="" method="POST">
<input type="hidden" name="_method" value="PUT">
<div class="row">
<div class="col-md-3" >
<label for="title" >title</label>
<input id="title" type="text" class="form-control" name="title" value="" required autofocus>
</div>
<div class="col-md-3">
<label for="description" >description</label>
<input id="description" type="text" class="form-control" name="description" value="" required>
</div>
</div>
<br>
<div class="row">
<div class="col-md-12">
<button type="submit" class="btn btn-primary" >
Edit
</button>
</div>
</div>
</form>
Error :
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire