mirror of
https://github.com/10h30/MoveMate.git
synced 2026-06-05 15:07:35 +09:00
Add ToggleComplete for TaskController
This commit is contained in:
@@ -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
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,18 +9,25 @@
|
||||
<div class="mb-5">
|
||||
<a class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" href="/task/create">Create new task</a>
|
||||
</div>
|
||||
|
||||
<div class="mb-5">
|
||||
Progress: {{ $completedTasks}} / {{ $totalTasks }} completed.
|
||||
</div>
|
||||
@foreach ($tasks as $task)
|
||||
<div class="block border-2 border-gray-500 p-2">
|
||||
<div><a href="/task/{{ $task->id }}">
|
||||
<h3 class="text-2xl tracking-tight text-blue-800">{{ $task->name }}<h3>
|
||||
</a></div>
|
||||
<div><strong>Where to go:</strong> {{ $task->location }}</div>
|
||||
<div><strong>Time Estimate:</strong> {{ $task->time_estimate }}</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<div><a href="/task/{{ $task->id }}">
|
||||
<h3 class="text-2xl tracking-tight text-blue-800">{{ $task->name }}<h3>
|
||||
</a></div>
|
||||
<div><strong>Where to go:</strong> {{ $task->location }}</div>
|
||||
<div><strong>Time Estimate:</strong> {{ $task->time_estimate }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<p>{{ ($task->completed) ? "Completed" : "" }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
<div class="mt-2">{{$tasks -> links()}}</div>
|
||||
</x-layout>
|
||||
|
||||
$completedCount = Task::where('completed', true)->count();
|
||||
</x-layout>
|
||||
@@ -4,12 +4,21 @@
|
||||
|
||||
|
||||
<div>
|
||||
<div class="text-lg mb-4"> {{ $task->description }}</div>
|
||||
<div class="text-lg mb-4">
|
||||
<h2>What need to do </h2>
|
||||
<p class="text-sm">{{ $task->description }}</p>
|
||||
</div>
|
||||
<div><strong>Where to go:</strong> {{ $task->location }}</div>
|
||||
<div><strong>Time Estimate:</strong> {{ $task->time_estimate }} hour</div>
|
||||
<div><strong>Category:</strong> {{ $task->category->name }}</div>
|
||||
<div><strong>Owner:</strong> {{ $task->user->name }}</div>
|
||||
|
||||
<div class="mt-4 mb-4">
|
||||
<form action="/task/{{ $task->id }}/toggle" method="POST" class="d-inline" >
|
||||
@csrf
|
||||
@method('PATCH')
|
||||
<x-form-button>{{ (! $task->completed) ? 'Mark Completed' : "Greate! You nailed it!" }}</x-form-button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<a href="/task/{{ $task->id }}/edit" class="text-sm text-blue-600 dark:text-blue-500 hover:underline">Edit</a>
|
||||
|
||||
+2
-2
@@ -12,8 +12,6 @@ use Illuminate\Validation\Rules\Password;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
|
||||
|
||||
|
||||
Route::get('/', [TaskController::class, 'index']);
|
||||
Route::get('/task', [TaskController::class, 'index'])->name('task.index');
|
||||
Route::get('/task/create', [TaskController::class, 'create']);
|
||||
@@ -22,6 +20,8 @@ Route::post('/task/create', [TaskController::class, 'store'])->name('task.create
|
||||
Route::delete('/task/{task}', [TaskController::class, 'destroy']);
|
||||
Route::get('/task/{task}/edit', [TaskController::class, 'edit']);
|
||||
Route::patch('/task/{task}', [TaskController::class, 'update']);
|
||||
Route::patch('/task/{task}/toggle', [TaskController::class, 'toggleComplete']);
|
||||
|
||||
|
||||
Route::get('/register', [UserRegisterController::class, 'register']);
|
||||
Route::post('/register', [UserRegisterController::class, 'store']);
|
||||
|
||||
Reference in New Issue
Block a user