30 lines
716 B
PHP
30 lines
716 B
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class PolicyListResource extends JsonResource
|
|
{
|
|
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$user = \Auth::guard('api')->user();
|
|
return [
|
|
'id' => $this->id,
|
|
'title' => $this->title,
|
|
'created_at' => $this->created_at->format('Y-m-d '),
|
|
'isFavorited' => $this->isFavoritedBy($user),
|
|
'type' => 'policy',
|
|
'area_id' => $this->areas()->pluck('china_area_id'),
|
|
];
|
|
}
|
|
|
|
}
|