0

i have simmilar question to this Laravel nova action - get current model instance on fields()

but with info from https://github.com/laravel/nova-issues/issues/1813

It is possible.

I use Laravel 7.x and nova 3.10

I have a resource with field "size" for example 3KG, 4KG

I have an action with (only on index rows) field "amount" (number field)

I want to user to be able only to put multiplication of "size" in "amount" and a field that display on action value of "size"

I tried in action fields:

    Text::make(__('Package'), 'size')
->default(function(){

//need to load value of current model resource "size" to inform user

        })
        ->readonly(),

    Number::make(__('Amount'), 'amount')
        ->sortable()
        ->min(1) // -> i need to change this based on "size" form model resource
        ->max(9999)
        ->step(1) // -> i need to change this based on "size" form model resource
        ->updateRules('nullable')
        ->rules('required', 'number')
        ->help(__('in kilograms')),

How to load this JS array "ConfirmActionModal['selectedResources'][0]" in laravel fields?

I'm not well in JS, how to load values into php ?

1 Answer 1

3

get model name:

$model = $request->viaResource;

get model ID:

$id = $request->viaResourceId;

example:

$post = $parent = \App\Models\Post::find($request->viaResourceId);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.