Nova Actions, i`m frustrated - empty resource on click #5647
-
|
Sorry I'm a little frustrated with Nova. I define an action on a Nova resource and the In the index view I can access This confuses me and I am now reading the model data separately to use it: class Post extends Resource
{
public static $model = \App\Models\Post::class;
[...]
public function actions(NovaRequest $request): array
{
/** @var Post $resource */
$resource = $request->selectedResources()->first() ?? $this;
// index $this is filled
// detail $this is filled
// detail + Action Click $this is not filled
return [
EMailAction::make($this->locale), // wont work on Detail + Action Click,
EMailAction::make($resource->locale), // will work on Detail + Action Click, but not on index if more than one is selected
];
}
}As I said this is very confusing to think in different dimensions (Index/Detail/Click/Index Select) here. Why doesn't Nova fill the I believe that there are more side effects that also do not work as expected. Is this now a bug a feature? Am i doing something wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Obviously, this would cause an issue when
EMailAction::make()->canSee(function (NovaRequest $request) {
return $request->selectedResourceIds()?->count() === 1;
})->showInline()->showOnDetail(), /**
* Perform the action on the given models.
*
* @param \Laravel\Nova\Fields\ActionFields $fields
* @param \Illuminate\Support\Collection $models
* @return mixed
*/
public function handle(ActionFields $fields, Collection $models)
{
$locale = $models->first()->locale; |
Beta Was this translation helpful? Give feedback.
-
|
New in 4.26.0 you can simplify the above suggestion using EMailAction::make()->sole(), |
Beta Was this translation helpful? Give feedback.
Obviously, this would cause an issue when
localecan now be multiple (different for each resource) but there's only a single instance ofEMailAction. You should only allow this action to be selected for following usage: