查询时,我想使用store_id而不是nd_001_store_id。我收到如下错误 : 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 和 store_id 未找到列错误谢谢,最诚挚的问候
1 回答
扬帆大鱼
TA贡献1799条经验 获得超9个赞
请尝试 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();
- 1 回答
- 0 关注
- 145 浏览
添加回答
举报
0/150
提交
取消