mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
65 lines
1.4 KiB
PHP
65 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Transformers;
|
|
|
|
use App\Models\Company;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use League\Fractal\Resource\Item;
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
class CompanyTransformer extends TransformerAbstract
|
|
{
|
|
|
|
|
|
/**
|
|
* List of all default includes
|
|
*/
|
|
protected array $defaultIncludes = [
|
|
'contact',
|
|
];
|
|
|
|
/**
|
|
* List of all possible includes
|
|
* @var array|string[]
|
|
*/
|
|
protected array $availableIncludes = [
|
|
|
|
'segments',
|
|
'employee',
|
|
'company_module',
|
|
'last_order',
|
|
'order_count',
|
|
'identification',
|
|
];
|
|
|
|
public function transform(Company $company): array
|
|
{
|
|
return [
|
|
'id' => $company->id,
|
|
'hash_id' => Crypt::encryptString($company->id),
|
|
'name' => $company->name,
|
|
'debtor' => $company->debtor,
|
|
'reference' => $company->reference,
|
|
'type' => $company->type,
|
|
'business_type' => (int)$company->business_type,
|
|
'status' => $company->status,
|
|
'created_at' => $company->created_at->format('d-m-Y')
|
|
];
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Include Contact
|
|
*
|
|
* @param Company $company
|
|
* @return Item
|
|
*/
|
|
public function includeContact(Company $company): Item
|
|
{
|
|
$contact = $company->contacts();
|
|
|
|
return $this->item($contact->first(), new ContactTransformer());
|
|
}
|
|
}
|