withCount('replies'); } public function getAll(): Collection { return $this->baseQuery() ->orderBy('order', 'asc') ->orderBy('created_at', 'desc') ->get(); } public function getAllForUnit(int $unitId): Collection { return $this->baseQuery() ->visibleToUnit($unitId) ->orderBy('order', 'asc') ->orderBy('created_at', 'desc') ->get(); } /** * Bulk-update phase + order for a set of cards (drag-and-drop persistence). * Expects: [['id' => int, 'phase' => string, 'order' => int], ...] */ public function reorder(array $items): void { foreach ($items as $item) { Kanban::where('id', $item['id'])->update([ 'phase' => $item['phase'], 'order' => $item['order'], ]); } } public function findById(int $id): ?Kanban { return $this->baseQuery()->find($id); } public function create(array $data): Kanban { $model = Kanban::create($data); return $this->findById($model->id); } public function update(int $id, array $data): ?Kanban { $model = Kanban::find($id); if (!$model) { return null; } $model->update($data); return $this->findById($model->id); } public function delete(int $id): bool { $model = Kanban::find($id); if (!$model) { return false; } return $model->delete(); } }