Laravel Fluent add select()s in separate places? Laravel Fluent add select()s in separate places? laravel laravel

Laravel Fluent add select()s in separate places?


For future reference, you can use the addSelect() function.

It would be good to have in the documentation, but you'll find it here in the API: http://laravel.com/api/4.2/Illuminate/Database/Query/Builder.html#method_addSelect


Yeah you just insert the block you wanna execute as a function....according to the documentation on Parameter Grouping , you can do like so...by passing the Where a function...

This code below probably wont do what you want, but, its something for you to build off of, and play around with.

DB::table('users')        ->where('name', '=', 'John')        ->orWhere(function($query)        {            $query->group_by($value);                  ->select(DB::raw('COUNT('.$value.') as count'));        })        ->get();


Try this:

$thing_query->groupBy($value)->get(DB::raw('COUNT('.$value.') as count'));

Also,if you are just trying to get the count and not select multiple things you can use ->count() instead of ->get()