Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Laravel Eloquent groupBy() AND also return count of each group

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 8.69k
    Comment on it

    We can also make our query on groupBy using Laravel 4.x.Let me demonstrate it by the following example.

    Suppose we have a table in which we have n number of users which are from different-different state and we have to find that how many users belong to particular state.Then we have to run the following query.

     $userInfo = DB::table('user')->select('state', DB::raw('count(*) as total'))->groupBy('state') ->get(); 
    

    Here In the above example we can count the employee of particular state by using groupBy.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: