2016-08-09 76 views
0

我僅在datetime中選擇月份部分時遇到問題。我在表格事務中有一個名爲payment_date的列。我想select * from transactiongroup by月的payment_date。我曾嘗試使用此代碼:僅從Laravel的Datetime中選擇月份

$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()

任何人都可以幫助我解決這個問題嗎?

謝謝。

回答

0

你應該把 - > 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(); 
+0

哦,我的壞了,感謝您的@Nour,但是,我得到新的錯誤在'DB :: raw('MONTH(payment_date)as monthPayment')'。我得到這樣的錯誤:'功能月(沒有時區的時間戳)不存在'。你能幫我處理這個錯誤嗎? –