| 123456789101112131415161718192021222324252627282930 |
- <?php
- namespace App\Http\Resources;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class NotificationResource extends JsonResource
- {
- public function toArray(Request $request): array
- {
- return [
- 'id' => $this->id,
- 'type' => $this->type,
- 'title' => $this->title,
- 'message' => $this->message,
- 'recipient' => $this->recipient,
- 'recipient_position_id' => $this->recipient_position_id,
- 'recipient_sector_id' => $this->recipient_sector_id,
- 'sent_count' => $this->when($this->sends_count !== null, $this->sends_count),
- 'seen_count' => $this->when($this->seen_count !== null, $this->seen_count),
- 'image_url' => $this->whenLoaded('media', fn() => $this->media->first()?->url),
- 'created_by' => $this->created_by,
- 'created_by_user' => $this->whenLoaded('createdBy', fn() => new UserResource($this->createdBy)),
- 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
- 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
- ];
- }
- }
|