Laravel Nova 显示用户友好的资源名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52262362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:02:34  来源:igfitidea点击:

Laravel Nova display user-friendly resource name

laravellaravel-nova

提问by Slimez

Let's say that I have a resource called "Resource_test". When I'm displaying that resource in Nova, that resource name (or "label") displays the name as-is which obviously isn't very user-friendly.

假设我有一个名为“Resource_test”的资源。当我在 Nova 中显示该资源时,该资源名称(或“标签”)按原样显示名称,这显然对用户不友好。

Is it possible to rename the "label" to "Resource Test" (without the underscore for example)?

是否可以将“标签”重命名为“资源测试”(例如不带下划线)?

It seems like they set the name in the file src\Nova.phpon the static function resourceInformationbut even though I change the name there, it doesn't seem to change the name on the site itself...

似乎他们src\Nova.php在静态函数的文件中设置了名称,resourceInformation但即使我在那里更改了名称,它似乎也没有更改站点本身的名称...

回答by Marten van Urk

You can override the static label method within the resource class like this:

您可以像这样覆盖资源类中的静态标签方法:

public static function label() {
    return 'Your own label';
}

You'll find your resource classes in the app/Novadirectory. Do not confuse these classes with the identically-named models! Adding the labelmethod to the model will not work.

您将在app/Nova目录中找到您的资源类。不要将这些类与同名模型混淆!将label方法添加到模型将不起作用。

You can take a look at the Nova\src\Resource.phpclass to view all the options.

您可以查看Nova\src\Resource.php类以查看所有选项。