KanbanReplyService.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Services;
  3. use App\Models\KanbanReply;
  4. use Illuminate\Database\Eloquent\Collection;
  5. class KanbanReplyService
  6. {
  7. public function getByKanban(int $kanbanId): Collection
  8. {
  9. return KanbanReply::with('user')
  10. ->where('kanban_id', $kanbanId)
  11. ->orderBy('created_at', 'asc')
  12. ->get();
  13. }
  14. public function create(int $kanbanId, int $userId, string $reply): KanbanReply
  15. {
  16. $model = KanbanReply::create([
  17. 'kanban_id' => $kanbanId,
  18. 'user_id' => $userId,
  19. 'reply' => $reply,
  20. ]);
  21. return $model->load('user');
  22. }
  23. public function update(int $kanbanId, int $id, string $reply): KanbanReply
  24. {
  25. $model = KanbanReply::where('kanban_id', $kanbanId)->findOrFail($id);
  26. $model->update(['reply' => $reply]);
  27. return $model->load('user');
  28. }
  29. public function delete(int $kanbanId, int $id): bool
  30. {
  31. $model = KanbanReply::where('kanban_id', $kanbanId)->findOrFail($id);
  32. return $model->delete();
  33. }
  34. }