Certainly! In Laravel Nova, you can conditionally hide the edit button on a per-row basis by overriding the authorizedToUpdate method on the resource. This method determines if the edit button should be displayed for a given resource instance.
Here's how you can do it:
- Open the Nova resource file for the model you want to conditionally hide the edit button.
- Override the
authorizedToUpdatemethod. - Add your custom logic to determine when the edit button should be hidden.
Here's an example:
namespace App\Nova;
use Laravel\Nova\Http\Requests\NovaRequest;
class YourResource extends Resource
{
// ...
/**
* Determine if the current user can update the given resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return bool
*/
public function authorizedToUpdate(NovaRequest $request)
{
// Add your condition here. For example, if the resource has a 'status' field:
if ($this->status == 'archived') {
return false;
}
// Otherwise, use the default authorization logic
return parent::authorizedToUpdate($request);
}
// ...
}
In the example above, the edit button will be hidden for rows where the status field is set to 'archived'. You can replace the condition with whatever logic applies to your specific use case.
Remember to import the NovaRequest at the top of your resource file if it's not already there.
This way, you can have fine-grained control over which records show the edit button in the index view of a Nova resource.