0

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');
}
Takichee
  • 105
  • 1
  • 1
  • 7
  • 2
    This is because your `Route::resource()` is using `index`, however, your method is using `task` which don't match. Please look at this post for more information: https://stackoverflow.com/questions/69250250/delete-not-working-on-laravel-8-controller/69252787#69252787 – Rwd Sep 23 '21 at 09:56

1 Answers1

1

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">
Rouhollah Mazarei
  • 3,969
  • 1
  • 14
  • 20