Today we will learn how to get subdays records in laravel. When you work with any laravel eCommerce application, dating application, etc. that time we need to show analytics in the application dashboard.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class UserController extends Controller
{
public function index()
{
$users = User::where('created_at', '>=', Carbon::now()->subDays(10))->get();
}
}
If you want to get or fetch previous month records in laravel. Use the below laravel eloquent query to get the last month records from the database table.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class UserController extends Controller
{
public function index()
{
$users = User::where('created_at', '>=', Carbon::now()->subMonth()->month)->get();
}
}
Thank You