首页 > 解决方案 > Laravel Nova 从另一个字段引用字段值

问题描述

据我所知,要引用 Nova 字段,您可以在字段函数中使用 $this 对象。

所以我有这段代码,我的问题是这些值是空的,不应该:

即使我的索引页面显示字段 origin_coordinates 和 destination_coordinates 的值。

你知道为什么 Measure 字段是空的,这是基于我提到的字段。

谢谢,

    BelongsTo::make('Warehouse')
        ->withoutTrashed()
        ->rules('required')
        ->sortable(),


    BelongsTo::make('Customer')
        ->withoutTrashed()
        ->rules('required')
        ->sortable(),

    BelongsToDependency::make('Consignee')
        ->dependsOn('customer', 'customer_id'),


    Text::make('origin_coordinates', function() {
        return $this->warehouse->longitude . ','. $this->warehouse->latitude;
    }),

    Text::make('destination_coordinates', function() {
        return $this->consignee->longitude . ',' . $this->consignee->latitude;
    }),

    RouteMeasures::make('Measures')    <---- Here is my problems this value is empty and should not
        ->route(
            $this->origin_coordinates,
            $this->destination_coordinates, 
            env('MAPBOX_ACCESS_TOKEN')
        ),

标签: laravellaravel-nova

解决方案


推荐阅读