How to Get Last 7 Days Record in Laravel?
This simple article demonstrates of laravel get last 7 days records. i explained simply about get last 7 days data in laravel. i explained simply step by step get last 7 days records in laravel. In this article, we will implement a laravel get last 7 days data from database.
we can easily get last 7 days records in laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 version.
i will show you simple code of controller method where we written code to getting last 7 days records using carbon laravel eloquent.
let's see controller code:
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();
I hope it can help you...
We are Recommending you
- Laravel Eloquent firstOrCreate Example
- Laravel Eloquent Group By Example
- Laravel Eloquent take() and skip() Query Example
- Laravel Eloquent whereNotBetween() Query Example
- Laravel Eloquent selectRaw() Query Example
- Laravel Eloquent whereRaw Condition Example
- How to Create and Use Query Scope in Laravel Eloquent
- How to use Union query with Laravel Eloquent?
- Laravel Many to Many Eloquent Relationship Tutorial
- Laravel - whereDate(), whereMonth(), whereDay() and whereYear() examples.
- Laravel Like Query Example using Eloquent Where Clause