Files
nexusphp/app/Http/Resources/CommentResource.php
2025-12-30 17:49:56 +07:00

28 lines
763 B
PHP

<?php
namespace App\Http\Resources;
use Carbon\CarbonInterface;
use Illuminate\Http\Resources\Json\JsonResource;
class CommentResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'text' => $this->text,
'updated_at' => format_datetime($this->editdate),
'created_at' => format_datetime($this->added),
'create_user' => new UserResource($this->whenLoaded('create_user')),
'update_user' => $this->when($this->editedby > 0, new UserResource($this->whenLoaded('update_user'))),
];
}
}