我仅从datetime
选择月份部分时遇到麻烦。我在表交易中有一列名为payment_date的列。我想在select * from transaction
和group by
个付款日期。我尝试使用此代码:
$selectedYearTrx = $connectDB->table('transaction')
->join('payment_channel','transaction.payment_channel_id','=','payment_channel.id')
->select('id','payment_date', 'payment_channel_id','amount',DB::raw('MONTH(payment_date) as monthPayment'))
->whereYear('payment_date', '=', $year)
->where('status','=','S')
->wherein('payment_channel_id', [1,2,3])
->where('currency','=','IDR')
->orderBy('id', 'desc')
->get()
->groupBy('payment_channel_id','id','monthPayment');
但是,我在分组依据的
monthPayment
中遇到错误。该错误称为成员函数groupby()。谁能帮我解决这个问题?
谢谢。
最佳答案
您应该在代码末尾添加-> get())
$selectedYearTrx = $connectDB->table('transaction')
->join('payment_channel','transaction.payment_channel_id','=','payment_channel.id')
->select('id','payment_date', 'payment_channel_id','amount',DB::raw('MONTH(payment_date) as monthPayment'))
->whereYear('payment_date', '=', $year)
->where('status','=','S')
->wherein('payment_channel_id', [1,2,3])
->where('currency','=','IDR')
->orderBy('id', 'desc')
->get()
->groupBy('payment_channel_id','id','monthPayment');
应该
$selectedYearTrx = $connectDB->table('transaction')
->join('payment_channel','transaction.payment_channel_id','=','payment_channel.id')
->select('id','payment_date', 'payment_channel_id','amount',DB::raw('MONTH(payment_date) as monthPayment'))
->whereYear('payment_date', '=', $year)
->where('status','=','S')
->wherein('payment_channel_id', [1,2,3])
->where('currency','=','IDR')
->orderBy('id', 'desc')
->groupBy('payment_channel_id','id','monthPayment')->get();