| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Services;
- use App\Models\Kanban;
- use Illuminate\Database\Eloquent\Collection;
- class KanbanService
- {
- private function baseQuery()
- {
- return Kanban::with(['createdByUser', 'responsibleUser', 'applicantUnit', 'targetUnit'])
- ->withCount('replies');
- }
- public function getAll(): Collection
- {
- return $this->baseQuery()
- ->orderBy('created_at', 'desc')
- ->get();
- }
- public function getAllForUnit(int $unitId): Collection
- {
- return $this->baseQuery()
- ->visibleToUnit($unitId)
- ->orderBy('created_at', 'desc')
- ->get();
- }
- 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();
- }
- }
|