Hello Dev
This is a very simple article demonstrates of laravel how get last 7 days records. I will explain it very simply about get last 7 days record in laravel. I will explain it now very simply step by step get last 7 days records in laravel. In this article, i will implement a laravel to get last 7 days data from our database.
We can easily get last 7 days record in laravel 6, laravel 7 and laravel 8 version.
I will show you now simple code of controller method where i written code to getting last 7 days records using carbon laravel eloquent.
Read Also: Laravel One to Many Eloquent Relationship
let’s see controller code:
Controller File:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class UserController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$date = Carbon::now()->subDays(7);
$users = User::where('created_at', '>=', $date)->get();
dd($users);
}
}
I hope it will help you. Also you can follow us on Facebook