Files
alrahma_sunday_school_api/app/Http/Resources/Messaging/MessageResource.php
T
2026-06-09 01:25:14 -04:00

32 lines
1.3 KiB
PHP

<?php
namespace App\Http\Resources\Messaging;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class MessageResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id ?? null,
'sender_id' => $this->sender_id ?? null,
'recipient_id' => $this->recipient_id ?? null,
'subject' => $this->subject ?? null,
'message' => $this->message ?? null,
'sent_datetime' => optional($this->sent_datetime)->toDateTimeString(),
'read_status' => (bool) ($this->read_status ?? false),
'read_datetime' => optional($this->read_datetime)->toDateTimeString(),
'message_number' => $this->message_number ?? null,
'priority' => $this->priority ?? null,
'attachment' => $this->attachment ?? null,
'status' => $this->status ?? null,
'semester' => $this->semester ?? null,
'school_year' => $this->school_year ?? null,
'sender_name' => $this->sender ? trim($this->sender->firstname.' '.$this->sender->lastname) : null,
'recipient_name' => $this->recipient ? trim($this->recipient->firstname.' '.$this->recipient->lastname) : null,
];
}
}