NotificationResource.php 1.1 KB

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Http\Resources;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. class NotificationResource extends JsonResource
  7. {
  8. public function toArray(Request $request): array
  9. {
  10. return [
  11. 'id' => $this->id,
  12. 'type' => $this->type,
  13. 'source' => $this->source,
  14. 'source_id' => $this->source_id,
  15. 'title' => $this->title,
  16. 'message' => $this->message,
  17. 'recipient' => $this->recipient,
  18. 'recipient_position' => $this->recipient_position,
  19. 'recipient_sector' => $this->recipient_sector,
  20. 'created_by' => $this->created_by,
  21. 'created_by_user' => $this->whenLoaded('createdBy', fn() => new UserResource($this->createdBy)),
  22. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  23. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  24. ];
  25. }
  26. }