我昨天已将Laravel从6.x更新到7.x,将Nova从2.x更新到3.x。但是,由于我这样做了,因此在使用id
时,ID::make()
不再显示在Nova的表上。甚至ID::make('ID', 'id')
,ID::make()->asBigInt()
或ID::make('ID', 'id')->asBigInt()
都不工作,我也不知道为什么。
这会影响我的所有Nova模型,而不是我在此处发布的模型。这只是一个示例模型,因为它非常苗条。
任何想法为何Nova都无法解析我模型的id
?使用Text::make('ID', 'id')
时,我看到了id
。但是为什么不使用ID::make()
?
这是我的模特:
namespace App;
use Gwd\SeoMeta\Traits\SeoSitemapTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
use Gwd\SeoMeta\Traits\SeoMetaTrait;
class Page extends Model
{
use SeoMetaTrait, SeoSitemapTrait;
protected static function boot()
{
parent::boot();
static::creating(function ($page) {
if (!$page->user_id){
$page->user_id = Auth::id();
}
});
}
/**
* @Protected_variables
*/
protected $table = 'pages';
protected $guarded = ['id'];
protected $casts = [
'publish_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime'
];
/**
* @Public_variables
*/
/**
* @Relationships
*/
public function user()
{
return $this->belongsTo('App\User');
}
public function pageStatus()
{
return $this->belongsTo('App\PageStatus');
}
public function pageType()
{
return $this->belongsTo('App\PageType');
}
这是我的Nova型号:
<?php
namespace App\Nova;
use Epartment\NovaDependencyContainer\HasDependencies;
use Epartment\NovaDependencyContainer\NovaDependencyContainer;
use Froala\NovaFroalaField\Froala;
use Gwd\SeoMeta\SeoMeta;
use Illuminate\Http\Request;
use Inspheric\Fields\Indicator;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\DateTime;
use Pdewit\ExternalUrl\ExternalUrl;
use App\PageStatus;
class Page extends Resource
{
use HasDependencies;
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = \App\Page::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'title';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'title',
'slug'
];
/**
* 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')
->rules('required', 'max:255'),
ExternalUrl::make('Product Link', 'slug')
->onlyOnDetail(),
Text::make('Slug', 'slug')
->hideFromIndex()
->creationRules('unique:pages,slug')
->rules('required', 'alpha_dash', 'max:80'),
Froala::make('Content')
->hideFromIndex()
->rules('required'),
Indicator::make('Status', function() {
return $this->pageStatus->status;
})
->labels([
'publish' => 'Publish',
'future' => 'Future',
'draft' => 'Draft',
'pending' => 'Pending',
'private' => 'Privat'
])
->colors([
'publish' => 'green',
'future' => 'purple',
'draft' => 'blue',
'pending' => 'orange',
'private' => 'red'
]),
BelongsTo::make('Status', 'pageStatus', 'App\Nova\PageStatus')
->onlyOnForms(),
NovaDependencyContainer::make([
DateTime::make('When to Publish', 'publish_at')
->format('DD.MM.YYYY @ HH:MM:SS')
->rules('required', 'date_format:Y-m-d H:i:s')
])->dependsOn('pageStatus', PageStatus::getIdByStatus('future')),
BelongsTo::make('Type', 'pageType', 'App\Nova\PageType')
->viewable(false)
->sortable(),
BelongsTo::make('User', 'user'),
SeoMeta::make('SEO', 'seo_meta'),
];
}
/**
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function cards(Request $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function filters(Request $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function lenses(Request $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function actions(Request $request)
{
return [];
}
}
这是我的移民:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pages', function (Blueprint $table) {
$table->increments('id');
$table->unsignedBigInteger('user_id')->index();
$table->char('title')->index();
$table->char('slug')->index()->unique();
$table->text('content');
$table->unsignedBigInteger('page_type_id')->index();
$table->unsignedBigInteger('post_category_id')->index()->nullable();
$table->unsignedBigInteger('page_status_id')->index();
$table->timestamp('publish_at')->nullable();
$table->softDeletesTz();
$table->timestamps();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('restrict');
$table->foreign('page_type_id')
->references('id')
->on('page_types')
->onDelete('restrict');
$table->foreign('post_category_id')
->references('id')
->on('post_categories')
->onDelete('restrict');
$table->foreign('page_status_id')
->references('id')
->on('page_statuses')
->onDelete('restrict');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('pages');
}
}
放荡
答案 0 :(得分:0)
遇到了同样的问题,我通过更新 3rd party nova 包来修复它 - 在我的情况下 optimistdigital/nova-sortable 从 1.6.2 到 2.4.0。希望它会有所帮助:)