У меня в приложении есть ресурс Product API, например:
/**
* Transform the resource collection into an array.
*
* @param Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'desc' => $this->desc,
'color' => $this->color,
'amount' => $this->amount,
'available' => $this->available,
'createdAt' => $this->created_at,
'updatedAt' => $this->updated_at,
];
}
У меня мало ролей в приложении, например, admin, viewer. Когда администратор получает доступ к API, API возвращает все поля, но когда зритель обращается к API, он возвращает только ограниченные поля.
Как я могу справиться с этим, используя Gates & Policies
?
Могу ли я сделать что-то подобное
'createdAt' => $this->when($this->authorize('product.list'), $this->created_at)