php - ID 字段不显示(在 Larave 从 6.x 更新到 7.x 和 Nova 2.x 到 3.x 之后)
问题描述
我昨天已将 Laravel 从 6.x 更新到 7.x,将 Nova 从 2.x 更新到 3.x。但是,由于我这样做了,所以id
在使用ID::make()
. 甚至没有ID::make('ID', 'id')
,ID::make()->asBigInt()
或者ID::make('ID', 'id')->asBigInt()
正在工作,我不知道为什么。
这会影响我所有的 Nova 模型,而不是我在这里发布的模型。这只是一个示例模型,因为它非常纤薄。
为什么 Nova 无法解析id
我模型的 s 有什么想法吗?使用时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');
}
这是我的新星模型:
<?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');
}
}
亲切的问候
解决方案
有同样的问题,我通过更新 3rd 方 nova 包来修复它——在我的例子中,optimistdigital/nova-sortable从 1.6.2 到 2.4.0。希望它会有所帮助:)
推荐阅读
- r - 在 R Shiny 中,如何将用户输入从侧边栏面板移动到模式对话框中?
- python - 获得在 Python 中填充的有效 oauth_signature 的绝对最少代码
- mysql - 如何确定在 MySQL 表中发生特定插入的服务器 IP?
- amazon-web-services - 7mb 以上 Glue 爬虫未创建表并跳过
- ruby-on-rails - SimpleForm 版本的 :scope
- python - 在 Flask 应用程序中将数据从 MySQL 解析为 json 文件
- c - 使用Shell Builtins 使用switch 的分段错误
- numbers - 删除R中单词中的反斜杠
- azure-devops - Azure DevOps:如何将工作项链接到现有构建?
- ruby-on-rails - 是否有用于按属性分组并查找具有两个不同属性的组的 Ruby/Rails 子句?