In this example, we will see how to get the last 7 days record in laravel 8. You can simply get the last 7 days record using laravel 8 eloquent model. In PHP, you can use INTERVAL to get the last 7 days record from the database table. Also, we can see how to get last week's records in laravel 6/7/8 using Carbon functions.
For MySQL query, we are INTERVAL operator. It is mainly used to calculate the date and time values.
So, let's see get the last 7 days data in laravel 6, laravel 7 and laravel 8. how to get last 7 days record in PHP, how to get last 7 days record in MySQL.
SQL query to get records from the last 7 days in MySQL.
select * from users where created_at > now() - INTERVAL 7 day;
In laravel, we are using the carbon subdays function to get the last 7 days records.
$date = \Carbon\Carbon::today()->subDays(7);
$users = User::where('created_at','>=',$date)->get();
You might also like :
In this article, I will give you an example of the TinyMCE editor, Tinymce editor is a rich-text open-source editor,&nbs...
Jun-18-2020
in this tutorial, we see how to get last 30 days record in laravel 8. You can simply get the last 30 days reco...
Feb-02-2022
In this article, we will see how to create a calendar event in laravel 9 using ajax. Here, we will learn how to add...
Dec-28-2022
As an Angular 15 developer, I understand the importance of incorporating image upload functionality with a progress bar...
Jun-21-2023