资源$ title的作用和用法?

问题描述 投票:0回答:1
class OpsServer extends Resource
{


    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = \App\OpsServer::class;


    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'name';

$ title资源有什么用途,如何使用?

我认为它无能为力

laravel laravel-nova
1个回答
0
投票

当资源显示在搜索结果中时,结果将显示资源的“标题”。例如,User资源可以使用name属性作为其标题。然后,当资源显示在全局搜索结果中时,将显示该属性。

<<

要自定义资源的“标题”属性,可以在资源类上定义title属性:

/** * The single value that should be used to represent the resource when being displayed. * * @var string */ public static $title = 'name';

或者,您可以覆盖资源的title方法:

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

© www.soinside.com 2019 - 2024. All rights reserved.