【发布时间】:2021-02-17 19:10:54
【问题描述】:
SQLSTATE[42S22]: 找不到列: 1054 未知列 'notices.notice_category_id' in 'where 子句' (SQL: select * from notices where notices.notice_category_id = 1 and notices.@ 987654325@ 不为空且notices.deleted_at 为空)
This is notices table migration
public function up()
{
Schema::create('notices', function (Blueprint $table) {
$table->id();
$table->text('subject');
$table->integer('category_id');
$table->date('date');
$table->timestamps();
});
}
notice category table
public function up()
{
Schema::create('notice_categories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
model for noitceCategory
public function notices()
{
return $this->hasMany(Notice::class);
}
notice model
public function noticeCategory()
{
return $this->belongsTo(NoticeCategory::class);
}
我正在尝试使用以下代码进行计数
$noticecategory->notices->count();
``
tell me if any other information are required
【问题讨论】: