Let's say I have action "Ban" for Product resource and Product model has is_banned field. There is no need to show "Ban" action on details page of Product that is already banned (is_banned=1).
Laravel Nova documentation provides example of hiding actions based on whether or not admin is authorized to perform it:
public function actions(Request $request)
{
return [
(new Actions\EmailAccountProfile)->canSee(function ($request) {
return $request->user()->can(
'emailAnyAccountProfile', User::class
);
}),
];
}
But it doesn't cover how can I get current resource's model instance in the closure I provide for canSee resolution when this method is called in the context of a single resource (on it's details page).
actions() method is where we register available actions and in my case belongs to Product Nova resource class, but it doesn't have access to Eloquent model's context neither.
How can this be achieved?