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
$revenueMonth = Callback::where('created_at', '>=', Carbon::today()->startOfMonth()->subMonth())->sum('payment');
Laravel Get Last Month records Use the below laravel eloquent query to get the last month records from the database table. User::whereMonth('created_at', '=', Carbon::now()->subMonth()->month)->get(['name','created_at']); This query uses laravel method whereMonth() and get().
You may try something like this: $dogs = Dogs::orderBy('id', 'desc')->take(5)->get(); Use orderBy with Descending order and take the first n numbers of records.
Try this solutions:
$revenueMonth = Callback::where(
'created_at', '>=', Carbon::now()->subDays(30)->toDateTimeString()
);
You get all Callback for last 30 days.
$revenueMonth = Callback::where(
'created_at', '>=', Carbon::now()->firstOfMonth()->toDateTimeString()
);
Get for current month.
$revenueMonth = Callback::where(
'created_at', '>=', Carbon::now()->startOfMonth()->subMonth()->toDateString()
);
Get for start last month.
UPDATED
$revenueMonth = Callback::where(
'created_at', '>=', Carbon::now()->subMonth()->toDateTimeString()
);
This is what are you looking for :)
Hope it will help you:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With