简体   繁体   中英

LARAVEL production.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column

when querying, I wanted to use store_id instead of nd_001_store_id. I get the error as below production.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'store_id' in 'where clause'

$user_store_id = Session::get('user_store_id'); //for example 6
$a = "2020-06-20 13:00:00";
$b = "2020-07-05 13:00:00";
$sales_types = ['retail', 'wholesale'];
$invoice_items_stock_ids = InvoiceItems::select(
    'nd_001_stock_id AS stock_id',
    'nd_000_store_id AS store_id',
    DB::raw("CONCAT(add_date_store, ' ', add_hours_store) AS date_range")
)->where(function ($query) use ($user_store_id) {
    $query->where('store_id', '=', $user_store_id);
})->orWhere(function ($query) use ($a, $b) {
    $query->where('date_range', '>=', $a)
            ->where('date_range', '<=', $b);
})
->whereIn('type', $sales_types)->get();

date_range and store_id Column not found error

Thanks, Best Regards

please try whereRaw

$invoice_items_stock_ids = InvoiceItems::select(
    'nd_001_stock_id AS stock_id',
    'nd_000_store_id AS store_id',
    DB::raw("CONCAT(add_date_store, ' ', add_hours_store) AS date_range")
)->where(function ($query) use ($user_store_id) {
    $query->whereRaw('store_id', '=', $user_store_id);
})->orWhere(function ($query) use ($a, $b) {
    $query->whereRaw('date_range', '>=', $a)
            ->whereRaw('date_range', '<=', $b);
})
->whereIn('type', $sales_types)->get();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM