epartment / nova-dependency-container

A Laravel Nova field container allowing to depend on other fields values
MIT License
382 stars 163 forks source link

break out traits to fix Action vs ActionRequest usage #157

Closed ragingdave closed 3 years ago

ragingdave commented 3 years ago

This fixes a seemingly outlier issue potentially related to opcache, where the ActionRequest is called on an Action.

The stacktrace here looks something like this:

Error Call to undefined method App\Nova\Actions\BulkLocationBrandExclude::action() 
    vendor/epartment/nova-dependency-container/src/HasDependencies.php:148 App\Nova\Actions\BulkLocationBrandExclude::validateFields
    vendor/laravel/nova/src/Http/Requests/ActionRequest.php:150 Laravel\Nova\Http\Requests\ActionRequest::validateFields
    vendor/laravel/nova/src/Http/Controllers/ActionController.php:42 Laravel\Nova\Http\Controllers\ActionController::store

The issue is that the validateFields function potentially used on on Action, doesn't properly handle that an action doesn't need to call $this->action()->fields() and instead could call $this->fields() directly.

This PR breaks up the monolithic HasDependencies into multiple smaller traits, and specifically documents how to use the Dependency Container in an Action.

Maybe this is actually enabling using dependency on actions