Search code examples
laravel-novalaravel-authorization

Laravel Nova: How to hide fields only when updating the resource


I know I can hide some fields with canSee method:

Text::make('Something')
    ->canSee(function ($request) {
        return $request->user()->can('some ability');
    }),

And from the documentation, there is a canSeeWhen method where you can hide the field based on the abilities the user has:

canSeeWhen('viewProfile', $this);

But these methods work for every situation, for example if I define the canSee method on a field, the field is not seeable on index, detail, creating, and updating pages.

I want to hide some fields specifically when the user is editing the resource.

How can I do that?


Solution

  • I got it. You can use hideWhenUpdating method.

    Text::make('Something')->hideWhenUpdating();
    

    Other methods are:

    hideFromIndex
    hideFromDetail
    hideWhenCreating
    hideWhenUpdating
    onlyOnIndex
    onlyOnDetail
    onlyOnForms
    exceptOnForms