A
A
Abubakr2020-12-14 13:26:40
Laravel
Abubakr, 2020-12-14 13:26:40

When using the hideWhenCreating (and/or hideWhenUpdating) method in the fields method, how can I make the return set type an array?

There is a resource app\Nova\Resources\Client.php

This is how the fields method of this resource looks like:

public function fields(Request $request)
    {
        return [
            UUID::make('id')->hideWhenCreating()->hideWhenUpdating(),
            Text::make('SomeName', 'name'),
            BelongsTo::make( 'Users', "user", User::class)
        ];
    }

The return set type is an array, but when I use hideWhenCreating() or hideWhenUpdating() the type becomes an object.

In the browser console:
1) Not using hideWhenCreating() or hideWhenUpdating():
5fd734f3d60e2443379154.png

2) Using hideWhenCreating() or hideWhenUpdating():
5fd7352b2c3aa243981309.png

In the second step, the first "id" field is removed from the array, the array now starts at one, hence a non-array .

Wrapped the returned array in array_values, didn't help.

Where to look for the cause of the problem?

Version Laravel 8, Nova 3.15, PHP 7.4+.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question