[英]ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause'
I have a Laravel-Page and since i want to add a "soft delete" with the active field in the DB i get that error:我有一个 Laravel-Page,因为我想在数据库中的活动字段中添加一个“软删除”,所以我收到了这个错误:
emails.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from
categories
where (0
= active and1
= is active) order byname
asc)emails.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from
categories
where (0
= active and1
= is active) order byname
asc)
-> which causes a error 500 obviously -> 显然会导致错误 500
and I have no plan how to fix this cause it looks like everything is fine.我没有计划如何解决这个问题,因为看起来一切都很好。
DB-Layout数据库布局
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('image')->nullable();
$table->string('description')->nullable();
$table->unsignedBigInteger('userID')->nullable();
$table->string('active', 20)->default('is active');
$table->timestamps();
});
Model:模型:
protected $table = 'categories';
protected $fillable = ['id', 'name', 'image', 'description', 'userID', 'active', 'created_at', 'updated_at'];
Usage(as sample for all other):用法(作为所有其他示例):
$categories = DB::table('categories')
->where(['active', 'is active'])
->orderBy('name', 'asc')
->get();
or something like this:或类似的东西:
->where(['categoryID', $category->id], ['active', 'is active'])
This code is causing error.此代码导致错误。
$categories = DB::table('categories')
->where(['active', 'is active'])
->orderBy('name', 'asc')
->get();
Eloquent is expecting your where array to be in key
and value
pair.机锋期待您的其中阵列是在
key
和value
对。 As you have not given it, it is using index
as column name.由于您没有给出它,它使用
index
作为列名。
You should place it like this:你应该像这样放置它:
$categories = DB::table('categories')
->where('active', 'is active') //will also work ->where('active', '=', 'is active')
->orderBy('name', 'asc')
->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.