ziffmedia / nova-select-plus

A Laravel Nova Select Field
MIT License
91 stars 26 forks source link

Creating a Select Plus Component on a Panel causes the Select Plus Controller to throw errors #25

Closed spam-n-eggs closed 3 years ago

spam-n-eggs commented 3 years ago

Steps to Reproduce:

  1. Create a small nova app.
  2. Create three models.
  3. Add the select plus component to a panel to group it (For my case, I used epartment/nova-dependency-container).
  4. View the nova form for the model.
  5. Observe that the panel as well as the controller throw errors.

Further investigation:

I looked into this, and it looks like the issue is in the controller.
The code below assumes that the SelectPlus Component is at the top level and not on any panels:

  /** @var SelectPlus $field */
        $field = $request->newResource()
            ->availableFields($request)
            ->where('component', 'select-plus')
            ->where('attribute', $relationship)

The correct call may be updateFields($request) but it requires more investigation to be sure.

spam-n-eggs commented 3 years ago

After looking at this further it looks like it may be limited to nova-dependency-container. I am currently working on a Pull Request to address this issue.

ralphschindler commented 3 years ago

Hey, glad to hear. If you don't get to it before the end of the week, I have some time slated to look at this. Thanks!

ralphschindler commented 3 years ago

This issue is specific to the nova-depedency-container, and I think the proposed fix is slightly problematic in that it is specific to that one package.

My issue with it is that meta.fields is proprietary only to the department/nova-dependency-container. Fortunately, it looks like the author has thought about (potentially) issues like this and there is an easy solutions.

In your Resource do the following:

// import:

use Illuminate\Support\Facades\Route;

// inside Resource body at top:

    use HasDependencies {
        doesRouteRequireChildFields as hasDependenciesDoesRouteRequireChildFields;
    }

    protected function doesRouteRequireChildFields(): bool
    {
        return $this->hasDependenciesDoesRouteRequireChildFields()
            || Route::currentRouteAction() == 'ZiffMedia\NovaSelectPlus\Controller@options';
    }

This will ensure that child fields are included in the ->availableFields() call that the Controller is doing to find the field.

Hope this finds you well, thanks for the report (and subsequent PR as it helped me understand the ultimate issue, even though it was not merged.)