Laravel (7.x) nova (3.10) 操作 - 获取字段上的当前模型实例()

Laravel (7.x) nova (3.10) action - get current model instance on fields()

我有类似的问题Laravel nova action - get current model instance on fields()

但有来自 https://github.com/laravel/nova-issues/issues/1813

的信息

有可能。

我使用 Laravel 7.x 和 nova 3.10

我有一个资源字段为“尺寸”,例如 3KG、4KG

我有一个操作(仅在索引行上)字段“金额”(数字字段)

我希望用户只能将“大小”乘以“金额”,并在“大小”的操作值上显示一个字段

我在操作字段中尝试过:

    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')),

如何在 laravel 字段中加载此 JS 数组“ConfirmActionModal['selectedResources'][0]”?

我的 JS 不太好,如何将值加载到 php?

获取模型名称:

$model = $request->viaResource;

获取模型 ID:

$id = $request->viaResourceId;

示例:

$post = $parent = \App\Models\Post::find($request->viaResourceId);