31 lines
850 B
PHP
31 lines
850 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class NotificationResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
$data = is_array($this->data) ? $this->data : [];
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'type' => $data['type'] ?? $this->type,
|
|
'category' => $data['category'] ?? 'account',
|
|
'title' => $data['title'] ?? __('api.notifications.default_title'),
|
|
'body' => $data['body'] ?? '',
|
|
'url' => $data['url'] ?? null,
|
|
'readAt' => $this->read_at?->toISOString(),
|
|
'createdAt' => $this->created_at?->toISOString(),
|
|
];
|
|
}
|
|
}
|