SupportReplyService.php 836 B

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