How to get last year records count with month wise in Laravel
You can get last year records count with month name in Laravel. You can use DB::raw with Laravel eloquent to get the records count created in specific month with month name.
Fetch month wise last year data
$users = App\Models\User::select(DB::raw("(COUNT(*)) as count"),DB::raw("MONTHNAME(created_at) as monthname")) ->whereYear('created_at', date('Y', strtotime('-1 year'))) ->groupBy('monthname') ->get();0
This code snippet will help you to get the last year data with month wise.
Random Code Snippet Queries: Laravel
- How to create project_user pivot table in laravel
- How to get user information using hootlex/laravel-friendships package in laravel
- Method Illuminate\Http\Request::validated does not exist
- How to get single column value in laravel
- How to insert dynamic values to additional column with pivot column in pivot table on multiple records
- 419 page expired error in Laravel
- Get 30 days older records from table in laravel
- How to get selected categories on edit record with Select2
- External link not working in laravel blade
- How to authenticate admin users in Laravel ?
- Class 'App\Rules\Hash' not found in Laravel
- SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
- Pass variable from blade to controller Laravel
- Laravel change date format
- How to upload image in laravel 8
- How to update record after save method in Laravel
- How to restore deleted records in laravel
- How to prevent host header attack in Laravel
- Php artisan make model, factory, migration and controller in single command
- How to display 1 day ago in comments in laravel view
- Call to a member function update() on null
- Laravel hasmany select not working
- Get the post details if it has at least one comment in comments table
- Update record after find method in lavavel
- Target class [App\Http\Controllers\Auth\Request] does not exist.