mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-20 04:54:12 +00:00
35 lines
741 B
PHP
35 lines
741 B
PHP
<?php
|
|
|
|
namespace App\Library;
|
|
|
|
use Spatie\Fractalistic\ArraySerializer;
|
|
|
|
class DefaultFractalSerializer extends ArraySerializer
|
|
{
|
|
/**
|
|
* @param $resourceKey
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
public function collection($resourceKey, array $data):array
|
|
{
|
|
if ($resourceKey) {
|
|
return $resourceKey == 'include' ? $data : [$resourceKey => $data];
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* @param $resourceKey
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
public function item($resourceKey, array $data):array
|
|
{
|
|
if ($resourceKey) {
|
|
return $resourceKey == 'include' ? $data : [$resourceKey => $data];
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
} |