Get last week data in Laravel
Created at 18-Nov-2021 ,
By samar
Get last week data in Laravel
In this session, we’ll try our hand at solving the "Get last week data in Laravel" puzzle by using the computer language.
You can get last week data in Laravel. Sometimes you have to get the records which are created at previous week of the current month, in that case you can use whereBetween() method to get the last week records from the database table.-
Get last week (Saturday to Sunday) created users record in Laravel
--PATH routes\web.phpRoute::get('/get-last-week-users', function(){ $previous_week = strtotime("-1 week +1 day"); $start_week = strtotime("last sunday midnight",$previous_week); $end_week = strtotime("next saturday",$start_week); $start_week = date("Y-m-d",$start_week); $end_week = date("Y-m-d",$end_week); $users = App\Models\User::whereBetween('created_at', [$start_week, $end_week])->get(); dd($users); });
-
Get previous 7 days data using today() and subDays() method on Carbon in Laravel
$date = \Carbon\Carbon::today()->subDays(7); $users = App\Models\User::where('created_at','>=',$date)->get(); dd($users);
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- How to automatically update the timestamp of parent model in Laravel
- Create user in Laravel using tinker
- How to check records exist in loaded relationship in Laravel blade view
- How to add class to tr in table using foreach in laravel
- How to pass query string to url in laravel
- Get only 10 records from table in laravel
- Pagination in laravel
- Composer\Exception\NoSslException
- Get laravel version
- How to add columns in existing table using migration in laravel
- How to get data from two tables in laravel
- How to check query string exists or not in laravel blade
- Ajax POST request in laravel
- Remove array keys and values if it does not exist in other array in Laravel
- How to add background image to div using Tailwindcss, Vite in Laravel Environment
- Run artisan command to generate key in laravel
- How to get only time from created_at in laravel
- How to check column value of a record is null or not in laravel
- How to get column names from table in Laravel
- SQLSTATE[42000]: Syntax error or access violation: 1055
- Rendering HTML from database table to view in Laravel
- How to start websocket server in laravel
- Convert input array to comma-separated string in laravel controller
- Add a subselect based on relationship using withAggregate method
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table