How to get last month records in Laravel
How to get last month records in Laravel
Hello everyone, in this post we will look at how to solve "How to get last month records in Laravel" in programming.
You can get last month records from a table in Laravel. Laravel provides the whereMonth() method which helps you to get the records from table which are created in previous month.-
Get last month records from users table in Laravel 8
User::whereMonth('created_at', '=', \Carbon\Carbon::now()->subMonth()->month)->get();
Code Examples
routes\web.php
Route::get('/get-last-month-records', function(){ $users = App\Models\User::whereMonth('created_at', '=', \Carbon\Carbon::now()->subMonth()->month)->get(); dd($users); });
You can get the records from users table which are created at last month. Simply visit /get-last-month-records and you can get the records from users table which are created at previous month.
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
- Rendering HTML from database table to view in Laravel
- PhpMyAdmin - Error The mysqli extension is missing
- How to validate website url in laravel using validaiton
- Get ids in array from users table
- Remove several global scope from query
- How to pass external link in laravel blade to anchor tag
- Laravel csrf token mismatch for ajax POST Request
- Conditional where clause in Laravel
- Display first n record from collection in laravel view
- Laravel file size validation not working
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- Get today records in Laravel
- Laravel save object to database
- How to create controller in laravel
- How to call model in blade laravel
- How to get route name on visit URL in laravel
- How to get only time from created_at in laravel
- Pagination in laravel
- How to get last record from object collection in laravel
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- How to add script on specific view file in laravel while extending layout
- Laravel delete all rows older than 30 days
- How to disable timestamps in laravel
- How to change default timestamp fields name in Laravel