diff --git a/app/Http/Controllers/TodoController.php b/app/Http/Controllers/TodoController.php index cac6eb2..7979c17 100644 --- a/app/Http/Controllers/TodoController.php +++ b/app/Http/Controllers/TodoController.php @@ -70,6 +70,10 @@ */ public function destroy(Todo $todo) { + $todo->delete(); + + return redirect()->route('todo.index')->with('message.success', 'Todo deleted successfully!'); + // } } diff --git a/resources/views/todo/index.blade.php b/resources/views/todo/index.blade.php index 18b48f3..29a1250 100644 --- a/resources/views/todo/index.blade.php +++ b/resources/views/todo/index.blade.php @@ -17,7 +17,7 @@ @php - $ths = ['ID', 'Task', 'Created At', 'Updated At']; + $ths = ['ID', 'Task', 'Created At', 'Updated At', 'delete']; @endphp @foreach ($ths as $th) @@ -32,6 +32,15 @@ + @endforeach @@ -42,7 +51,8 @@ @csrf
- +
{{ $todo->task }} {{ $todo->created_at }} {{ $todo->updated_at }} +
+ @csrf + @method('DELETE') + {{-- 上の行は、DELETEリクエストを送信するために必要な@methodディレクティブです。 --}} + +
+