
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
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- Post table seeder laravel 10
- How to call model in blade laravel
- How to get session in blade Laravel ?
- Rendering HTML from database table to view in Laravel
- Laravel 11 sanctum api authentication example code
- Print query in laravel
- How to pass query string with pagination in laravel
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- Laravel get count with where condition
- How to fetch single row data from database in laravel
- Post model with title and body in laravel 8
- How to get last record from object collection in laravel
- How to get count of all records created at yesterday
- How to get route name on visit URL in laravel
- Laravel create default admin user
- Declaration of App\Models\Post::sluggable() must be compatible with Cviebrock\EloquentSluggable\Sluggable
- Import/Use Storage facade in laravel
- Retain selected value of select box in Laravel
- Get last record from table in laravel
- How to call Laravel route in jQuery
- Permanently delete a record in laravel
- Input file with max size validation in laravel
- Laravel file size validation not working
- Get Array of IDs from Eloquent Collection