Mig*_*ens 0 php laravel laravel-nova
在我的 Laravel Nova 项目中,我有一个 Page 和一个 PageTranslation(模型和资源)。在我的资源字段中添加 hasMany 时,在访问页面的详细信息时,我收到 404 错误。这是我的代码
这是我的页面资源
<?php
namespace App\Pages\Resources;
use Illuminate\Http\Request;
use Laravel\Nova\Resource;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\HasMany;
class Page extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = 'App\Pages\Models\Page';
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'working_title';
/**
* @var string
*/
public static $group = 'Pages';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id', 'working_title'
];
/**
* Eager load translations
*/
public static $with = ['translations'];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('Title', 'working_title')
->sortable()
->rules('required', 'max:256'),
HasMany::make('Translations', 'translations', \App\Pages\Resources\PageTranslation::class)
];
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 PageTranslation 资源
<?php
namespace Codedor\Pages\Resources;
use Illuminate\Http\Request;
use Laravel\Nova\Resource;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
class PageTranslation extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = 'Codedor\Pages\Models\PageTranslation';
/**
* Hide resource from Nova's standard menu.
* @var bool
*/
public static $displayInNavigation = false;
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('Locale')
->sortable()
->rules('required', 'max:256')
];
}
}
Run Code Online (Sandbox Code Playgroud)
我有点晚了,但是如果有人在使用方法中而Nova::resources不是resources方法中的资源路径时遇到此问题NovaServiceProvider,请确保将相关资源添加到列表中。
如果您想从侧边栏导航中隐藏资源,只需public static $displayInNavigation = false;在资源文件中使用
| 归档时间: |
|
| 查看次数: |
935 次 |
| 最近记录: |