Laravel 在setupCreateOperation中选择类型字段
我对Laravel背包还是新手,在创建页面时尝试提交时遇到了问题 Illumb\Database\QueryException SQLSTATE[42S22]:未找到列: 1054“where子句”中的未知列“post_types.post_id”(SQL: 从Laravel 在setupCreateOperation中选择类型字段,laravel,laravel-backpack,Laravel,Laravel Backpack,我对Laravel背包还是新手,在创建页面时尝试提交时遇到了问题 Illumb\Database\QueryException SQLSTATE[42S22]:未找到列: 1054“where子句”中的未知列“post_types.post_id”(SQL: 从post\u types中选择*其中post\u typespost\u id=52和 post\u typepost\u id不为空限制1) postcrude控制器 protected function setupCreateOper
post\u types
中选择*其中post\u types
post\u id
=52和
post\u type
post\u id
不为空限制1)
postcrude控制器
protected function setupCreateOperation()
{
CRUD::setValidation(PostRequest::class);
$this->crud->addField([
'label' => "Post Type",
'type' => 'select',
'name' => 'post_type_id',
'entity' => 'postType',
'attribute' => 'post_type_name',
'model' => "App\Models\PostType",
]);
// $this->crud->addField('post_type_id');
$this->crud->addField([
'label' => 'User',
'type' => 'relationship',
'name' => 'user_id',
'entity' => 'user',
'attribute' => 'id',
'model' => "App\Models\User",
]);
$this->crud->addField([ // Hidden
'label' => 'Dog Litter',
'name' => 'dog_litter_id',
'type' => 'relationship',
'entity' => 'DogLitter',
'attribute' => 'id',
'model' => "App\Models\DogLitter",
]);
$this->crud->addField([
'label' => "Dog",
'name' => 'dog_id',
'type' => 'select',
'entity' => 'dog',
'attribute' => 'registered_number',
'model' => "App\Models\dog",
]);
CRUD::field('post_title');
CRUD::field('post_description');
CRUD::field('price');
CRUD::field('status');
CRUD::field('interests');
$this->crud->addField([ // Upload
'name' => 'images',
'label' => 'Images',
'type' => 'upload_multiple',
'upload' => true,
'disk' => 'uploads', // if you store files in the /public folder, please omit this; if you store them in /storage or S3, please specify it;
// optional:
'temporary' => 10 // if using a service, such as S3, that requires you to make temporary URLs this will make a URL that is valid for the number of minutes specified
]);
/**
* Fields can be defined using the fluent syntax or array syntax:
* - CRUD::field('price')->type('number');
* - CRUD::addField(['name' => 'price', 'type' => 'number']));
*/
}
数据库迁移2021\u 04\u 15\u创建\u post.php
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained('users', 'id');
$table->foreignId('dog_id')->constrained('dogs', 'id');
$table->foreignId('dog_litter_id')->constrained('dog_litters', 'id');
$table->foreignId('post_type_id')->constrained('post_types', 'id');
$table->string('post_title', 250);
$table->string('post_description', 1000);
$table->integer('price')->nullable();
$table->string('status', 250);
$table->integer('interests')->default(0);
$table->timestamps();
$table->softDeletes();
});
}
public function up()
{
Schema::create('post_types', function (Blueprint $table) {
$table->id();
$table->string('post_type_name', 100);
});
}
2021\u 04\u 15\u 143908\u创建\u发布类型\u表格.php
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained('users', 'id');
$table->foreignId('dog_id')->constrained('dogs', 'id');
$table->foreignId('dog_litter_id')->constrained('dog_litters', 'id');
$table->foreignId('post_type_id')->constrained('post_types', 'id');
$table->string('post_title', 250);
$table->string('post_description', 1000);
$table->integer('price')->nullable();
$table->string('status', 250);
$table->integer('interests')->default(0);
$table->timestamps();
$table->softDeletes();
});
}
public function up()
{
Schema::create('post_types', function (Blueprint $table) {
$table->id();
$table->string('post_type_name', 100);
});
}
这里的流程是,我从createpage文件开始,其中所有selecttype字段都从其相关表中获取选项
其中Post与PostTypes具有1-1关系,请按如下方式更改Post类型模式:
public function up()
{
Schema::create('post_types', function (Blueprint $table) {
$table->id();
$table->string('post_type_name', 100);
$table->foreignId('post_id')->constrained('posts', 'id');
});
}
因为post_类型表中没有此类列post_id