Retrive all rows from last month (Laravel + Eloquent)

前端 未结 4 1649
Happy的楠姐
Happy的楠姐 2021-01-11 19:21

I\'m trying to get all records that belongs to last month, so far I managed to get all from last month but to date today, I\'m not sure how I can get only for last month

4条回答
  •  终归单人心
    2021-01-11 20:05

    UPDATED eloquent version of the your answer

    $fromDate = Carbon::now()->subMonth()->startOfMonth()->toDateString();
    $tillDate = Carbon::now()->subMonth()->endOfMonth()->toDateString();
    
    $revenueLastMonth = Callback::whereBetween('created_at',[$fromDate,$tillDate])->get();
    

提交回复
热议问题