Php 错误:SQLSTATE[42S22]:未找到列:“where子句”中的1054未知列“0”

Php 错误:SQLSTATE[42S22]:未找到列:“where子句”中的1054未知列“0”,php,html,mysql,laravel,Php,Html,Mysql,Laravel,我有一个Laravel页面,由于我想在DB中添加一个带有活动字段的软删除,我得到了这个错误: emails.ERROR:SQLSTATE[42S22]:未找到列:1054 where子句中的未知列“0”SQL:select*from categories where 0= 活动,1=按名称asc为活动订单 ->这显然会导致一个错误 我还没有计划如何解决这个问题,因为看起来一切都很好 数据库布局 Schema::create('categories', function (Blueprint $

我有一个Laravel页面,由于我想在DB中添加一个带有活动字段的软删除,我得到了这个错误:

emails.ERROR:SQLSTATE[42S22]:未找到列:1054 where子句中的未知列“0”SQL:select*from categories where 0= 活动,1=按名称asc为活动订单

->这显然会导致一个错误

我还没有计划如何解决这个问题,因为看起来一切都很好

数据库布局

 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();
    });
型号:

protected $table = 'categories';

protected $fillable = ['id', 'name', 'image', 'description', 'userID', 'active', 'created_at', 'updated_at'];
美国作为所有其他产品的样本:

$categories = DB::table('categories')
            ->where(['active', 'is active'])
            ->orderBy('name', 'asc')
            ->get();
或者像这样:

->where(['categoryID', $category->id], ['active', 'is active'])
$categories = DB::table('categories')
        ->where('active', 'is active') //will also work ->where('active', '=', 'is active')
        ->orderBy('name', 'asc')
        ->get();

此代码导致错误

$categories = DB::table('categories')
        ->where(['active', 'is active'])
        ->orderBy('name', 'asc')
        ->get();
Eloquent希望您的where数组位于键和值对中。因为您没有给出它,所以它使用索引作为列名

您应该这样放置它:

->where(['categoryID', $category->id], ['active', 'is active'])
$categories = DB::table('categories')
        ->where('active', 'is active') //will also work ->where('active', '=', 'is active')
        ->orderBy('name', 'asc')
        ->get();

尝试将->where['active','is active']更改为->where'active','is active',而不使用数组括号感谢您的工作,但是当我有这样的内容->where['categoryID',$category->id],'active','is active']将它们分隔为不同的where,或者使用关联数组,->where['categoryID'=>$category->id,'active'=>'是active']或者,您传入一个带有数组的数组:->其中['col1'、'='、'val1']、['col2'、'='、'val2']]。Laravels文档非常好……非常感谢