Nothing any update with put method in Laravel 8

Issue

I’m currently creating a simple todo-list in Laravel 8 and want to be able to update the items of the list.
My code doesn’t get any error but also nothing changes when I put the submit button.

index.blade.php:

<form action="{{ route('index.update', $task->id) }}" method="POST">
   @csrf
   @method('PUT')
   <td><input type="text" name="content" value="{{ $task->content }}" id=""></td>
   <td><input type="submit" value="Update"></td>
</form>

web.php:

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\TaskController;

Route::resource('index', TaskController::class);

TaskController.php:

public function update(Request $request, Task $task)
{
    $request->validate([
        'content' => 'required',
    ]);
    $task->update($request->all());

    return redirect('index');
}

Solution

As @rwd said, the problem is with the route definition. Change it to:

Route::resource('tasks', TaskController::class);

Then in the form:

<form action="{{ route('tasks.update', $task->id) }}" method="POST">

Answered By – Rouhollah Mazarei

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published