41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Purchase\Resources\AdminApp;
|
|
|
|
use App\Domains\Logging\Models\ValueChange;
|
|
use App\Domains\Purchase\Models\Purchase;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/** @mixin ValueChange */
|
|
class PurchaseModificationResource extends JsonResource
|
|
{
|
|
/** @return array<string, mixed> */
|
|
public function toArray(Request $request): array
|
|
{
|
|
/** @var Purchase|null $purchase */
|
|
$purchase = $this->whenLoaded('trackable');
|
|
$user = $this->whenLoaded('user');
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'purchase_id' => $this->trackable_id,
|
|
'attribute' => $this->attribute,
|
|
'old_value' => $this->old_value,
|
|
'new_value' => $this->new_value,
|
|
'changed_at' => $this->changed_at,
|
|
'actor_type' => $this->actor_type->value,
|
|
'purchase' => $purchase instanceof Purchase ? [
|
|
'id' => $purchase->id,
|
|
'customer_name' => $purchase->nombre_apellido,
|
|
'status' => $purchase->status,
|
|
] : null,
|
|
'modified_by' => $user ? [
|
|
'id' => $user->id,
|
|
'name' => $user->nombre_apellido,
|
|
'email' => $user->email,
|
|
] : null,
|
|
];
|
|
}
|
|
}
|