Laravel Select with Count Query with Group by Example

Laravel Select with Count Query with Group by Example

In this post we will give you information about Laravel Select with Count Query with Group by Example. Hear we will give you detail about Laravel Select with Count Query with Group by ExampleAnd how to use it also give you demo for it if it is necessary.

We always required to get count of number of records or number of inserted record of current month etc in laravel. We can use mysql count function in laravel eloquent. We have two way to get count of column value. first we can use laravel count() of query builder and another one we can use with directly with select statement using DB::raw(). I give you both example you can see and use any one as perfect for you.

Example 1:

$data = DB::table("click")->count();

print_r($data);

Example 2:

Also see:How to use groupby having with DB::raw in Laravel Query Builder?

$data = DB::table("click")

->select(DB::raw("COUNT(*) as count_row"))

->orderBy("created_at")

->groupBy(DB::raw("year(created_at)"))

->get();

print_r($data);

Hope this code and post will helped you for implement Laravel Select with Count Query with Group by Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

2  +  5  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US