| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Services;
- use App\Models\SupportReply;
- use Illuminate\Database\Eloquent\Collection;
- class SupportReplyService
- {
- public function getByTicket(int $ticketId): Collection
- {
- return SupportReply::with('user')
- ->where('ticket_id', $ticketId)
- ->orderBy('created_at', 'asc')
- ->get();
- }
- public function create(int $ticketId, int $userId, string $reply): SupportReply
- {
- $model = SupportReply::create([
- 'ticket_id' => $ticketId,
- 'user_id' => $userId,
- 'reply' => $reply,
- ]);
- return $model->load('user');
- }
- public function update(int $ticketId, int $id, string $reply): SupportReply
- {
- $model = SupportReply::where('ticket_id', $ticketId)->findOrFail($id);
- $model->update(['reply' => $reply]);
- return $model->load('user');
- }
- public function delete(int $ticketId, int $id): bool
- {
- $model = SupportReply::where('ticket_id', $ticketId)->findOrFail($id);
- return $model->delete();
- }
- }
|