
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
- Conditional where clause in Laravel
- Display first n record from collection in laravel view
- Laravel delete all rows older than 30 days
- Redirect to another view from controller in laravel
- Undefined property: stdClass::$title
- Laravel 9 route group with controller
- Route group with URI prefix using middleware and route name prefixes
- How to Access Array in blade laravel
- Extra Filter Query on Relationships in Laravel
- How to get data from two tables in laravel
- Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
- Laravel 7 login error message not showing
- Laravel file size validation not working
- Laravel route parameter
- Pass value from controller to model in laravel
- Insert dummy data in users table Laravel
- Property [user] does not exist on this collection instance
- Laravel recursive function in controller
- How to fill a column automatically while creating records in Laravel
- How to upload image in laravel 8
- Get all users except the followings users in overtrue laravel-follow
- Delete file from amazon s3 bucket using Laravel
- Ajax POST request in laravel
- How to get path from current URL in Laravel
- How to fetch single row data from database in laravel