29 lines
733 B
PHP
29 lines
733 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
class DynamicResource extends BaseResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
$result = parent::toArray($request);
|
|
if ($this->ledgers) {
|
|
$result['ledgers'] = LedgerResource::collection($this->ledgers);
|
|
}
|
|
if ($this->whenLoaded('participants')) {
|
|
$result['participants'] = ParticipantResource::collection($this->participants);
|
|
}
|
|
if ($this->whenLoaded('chat')) {
|
|
$result['chat'] = new ChatResource($this->chat);
|
|
}
|
|
return $result;
|
|
}
|
|
}
|