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 validation in laravel
- How to add script on specific view file in laravel while extending layout
- Get domain name in laravel
- Print query in laravel
- How to pass query string to url in laravel
- How to check if user has created any post or not in laravel
- Define variable and use in Laravel controller method
- How to check relationship is loaded or not in Laravel
- Laravel 9 route group with controller
- Generate random string lowercase in Laravel
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- Send post data from controller to view
- Global scope in Laravel with example
- How to get records in random order in laravel
- Order by multiple columns in Laravel
- Submit form without CSRF token in Laravel
- How to remove P tag from CkEditor in Laravel?
- Laravel get all records with pagination
- How to get specific columns using Laravel eloquent methods
- How to create new user without form submission in laravel
- How to delete record in Laravel with ajax
- Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused)"
- How to change default timestamp fields name in Laravel
- How to upload image in laravel 8
- How to upload multiple images after preview in laravel using cropper js