How to Get Month Wise Data in Laravel?

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

Hello Brother,

I am going to explain you lesson of how to get month wise data in laravel. you can see get month wise data in laravel. you can see how to get month wise record in laravel. This article goes in detailed on laravel get month wise data lesson. Hello Brother, Creating a basic lesson of laravel group by month and sum.

we can get month wise records in laravel 6, laravel 7 and laravel 8 application.

Hello Brother, i will give you very simple lesson of how to get month wise record in laravel. we will use MONTHNAME() and groupBy() in this lesson.

I have one created items table that structure as bellow you can see.

items table:

Controller Code:

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Http;

use App\Models\Item;

use Carbon\Carbon;

use DB;

class ITSController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$items = Item::select(

DB::raw("(COUNT(*)) as count"),

DB::raw("MONTHNAME(created_at) as month_name")

)

->whereYear('created_at', date('Y'))

->groupBy('month_name')

->get()

->toArray();

dd($items);

}

}

Result:-

Array

(

[0] => Array

(

[count] => 8

[month_name] => August

)

[1] => Array

(

[count] => 4

[month_name] => October

)

)

thank you very much for following up with me.

Tags

Recent Posts

Related Posts