Add ToggleComplete for TaskController

This commit is contained in:
Thuan Bui
2025-03-06 22:25:46 +09:00
parent 11826da4c9
commit da2c4eeb6d
5 changed files with 34 additions and 18 deletions
+4 -4
View File
@@ -10,10 +10,10 @@ use Illuminate\Support\Facades\Auth;
class TaskController extends Controller
{
public function index() {
$task = Task::latest('updated_at')->Paginate(20);
return view('task.index', [
'tasks' => $task
]);
$totalTasks = Task::count(); // Count all tasks
$completedTasks = Task::where('completed', true)->count(); // Coun
$tasks = Task::latest('updated_at')->Paginate(20);
return view('task.index', compact('tasks','totalTasks','completedTasks'));
}
public function show(Task $task) {
+1 -1
View File
@@ -18,7 +18,7 @@ class Task extends Model
if (is_null($task->completed)) {
$task->completed = false; // Ensure completed is false when creating a new task
}
$task->user_id = Auth::id(); // Set user_id automatically
$task->user_id = Auth::id(); // Set user_id automatically
});
}