Laravel

How to Get Last 10 Days Record in Laravel?

Laravel

How to Get Last 10 Days Record in Laravel?

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.

Laravel Get Last 10 Day Records :

<?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();
    }
}

Get Last Week Data in Laravel :

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