
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
- Display message with session flash using bootstrap alert class in laravel
- How to start websocket server in laravel
- On delete set foreign id column value null using migration in laravel 8
- Laravel pagination links with query string
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- Eager loading dynamically in laravel
- Laravel create table migration with model
- Laravel 5.4 save data to database
- Redirect to previous page or url in laravel
- How to check data inserted or deleted in pivot after toggle method
- Ajax GET request in laravel
- The POST method is not supported for this route. Supported methods: PUT.
- Send post data from controller to view
- Get all users except the followings users in overtrue laravel-follow
- Shorter syntax for whereHas with call back function in laravel
- Method Illuminate\Database\Eloquent\Collection::appends does not exist
- How to get all posts which contains comments in laravel
- Laravel clone model
- How to validate website url in laravel using validaiton
- After image selected get validation error in laravel
- Get current month records in laravel 7/8
- How to get last year records count with month wise in Laravel
- Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused)"
- Trying to access array offset on value of type null error in laravel
- Global scope in Laravel with example