mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Transformers;
|
|
|
|
use App\Http\Resources\UserResource;
|
|
use App\Models\Item;
|
|
use App\Models\Remark;
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
class RemarkTransformer extends TransformerAbstract
|
|
{
|
|
/**
|
|
* List of resources to automatically include
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $defaultIncludes = [
|
|
'commenter'
|
|
];
|
|
|
|
/**
|
|
* List of resources possible to include
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $availableIncludes = [
|
|
//
|
|
];
|
|
|
|
/**
|
|
* A Fractal transformer.
|
|
*
|
|
* @param Remark $remark
|
|
* @return array
|
|
*/
|
|
public function transform(Remark $remark): array
|
|
{
|
|
return [
|
|
'id' => $remark->id,
|
|
'owner_id' => $remark->owner_id,
|
|
'content' => $remark->content,
|
|
'created_at' => $remark->created_at->format('d-m-Y H:i'),
|
|
'long_ago' => $remark->created_at->diffForHumans()
|
|
];
|
|
}
|
|
|
|
/**
|
|
* load commenter
|
|
* @param Remark $remark
|
|
* @return \League\Fractal\Resource\Item
|
|
*/
|
|
public function includeCommenter(Remark $remark): \League\Fractal\Resource\Item
|
|
{
|
|
$user = $remark->commenter();
|
|
return $this->item($user, new UserTransformer());
|
|
|
|
}
|
|
}
|