55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Contact;
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class ContactResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'client_id' => $this->client_id,
|
|
'fournisseur_id' => $this->fournisseur_id,
|
|
'first_name' => $this->first_name,
|
|
'last_name' => $this->last_name,
|
|
'full_name' => $this->full_name,
|
|
'email' => $this->email,
|
|
'phone' => $this->phone,
|
|
'role' => $this->role,
|
|
'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
|
|
'updated_at' => $this->updated_at?->format('Y-m-d H:i:s'),
|
|
|
|
// Relations
|
|
'client' => $this->whenLoaded('client', function() {
|
|
return $this->client ? [
|
|
'id' => $this->client->id,
|
|
'name' => $this->client->name,
|
|
] : null;
|
|
}),
|
|
'fournisseur' => $this->whenLoaded('fournisseur', function() {
|
|
return $this->fournisseur ? [
|
|
'id' => $this->fournisseur->id,
|
|
'name' => $this->fournisseur->name,
|
|
] : null;
|
|
}),
|
|
];
|
|
}
|
|
|
|
public function with(Request $request): array
|
|
{
|
|
return [
|
|
'status' => 'success',
|
|
'message' => 'Contact récupéré avec succès',
|
|
];
|
|
}
|
|
}
|