【问题标题】:Multiple column names for $title in Laravel Nova selectLaravel Nova 中 $title 的多个列名选择
【发布时间】:2019-07-29 06:34:21
【问题描述】:

是否可以将多个列名分组并将它们用作选择 BelongsTo 中的标签/标题,我不想使用 ID 并且没有“名称”字段,例如有问题的表是像这样:

  • 国家
  • 状态
  • 成本

所以下拉菜单应该能够让用户看到这些名称,例如:


美国 |华盛顿 | $50.00

美国 |加利福尼亚 | $80.00

美国 |德州 | $30.00


【问题讨论】:

    标签: laravel laravel-nova


    【解决方案1】:

    Documentation says,您可以覆盖资源的标题方法:

    /**
     * Get the value that should be displayed to represent the resource.
     *
     * @return string
     */
    public function title()
    {
        return $this->name;
    }
    

    对于某些特定于表单的显示,您可以使用:

    BelongsTo::make('SomeModel', 'somemodel', 'App\Nova\SomeModel')
             ->display(function($someModel){ 
                 return $someModel->id.' wow so custom, much id'; 
             }),
    

    【讨论】:

    • 我只想覆盖表单屏幕上字段中的标题。您引用的文档是我收集的资源本身
    • 太棒了 - 非常感谢!你知道在索引视图中是否可以将这个“显示”作为“显示更多”展开
    • @user1983183 索引显示可以用 ->displayUsing() 更改,但不确定里面是否允许 html/link。
    • 不用担心 - 我将为索引视图构建第二个字段,并且为表单构建一个字段。再次感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    • 2021-12-11
    • 2023-04-04
    • 1970-01-01
    • 2017-10-09
    • 2020-08-06
    相关资源
    最近更新 更多