Tag : groupBy()


MySql comma separated column join in PHP Laravel 5

If we work in big application or project of Laravel Framework, sometimes we require to manage column value into comma separated because we can save memory of database. But if we store comma separated value in column with ids then it's difficult to inner join or left join and get records from another tables. However, SQL provide FIND_IN_SET() for checking value one by one, that way we can also search from comma separated value. FIND_IN_SET() will help to join with tables and we can simply get data. In this post, I will give you full example of how to get data from comma separated column table.....

By Hardik Savani | January 7, 2017 | | 4431 Viewer | Category : PHP Laravel MySql SQL
READ MORE

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

We most probably require to use group by having because if you work on small project then it's not need to use generally. But if you work with big project like e-commerce, social or ERP level project then you may require to use having clause. having clause, we can use simply if we have to compare with number or static value like as bellow: <pre> ->having("total_quantity","<",10) </pre> But we need to compare with 10 instead of column name then it can't directly use column name. At that time we should use DB::raw() with column name. In this example i want to show minimum quantity items, I .....

By Hardik Savani | July 6, 2016 | | 3969 Viewer | Category : Laravel
READ MORE

Group by year month example in Laravel 5 using Query Builder

Sometimes, we have created_at column with timestamp and we wanted to get with group by with month, that way we can use for chart. However, you can do it using mysql MONTH() function. we can use DB raw with mysql function and get group by monthly records. So, you can see bellow query and use it. <strong>Example:</strong> <pre class="prettyprint lang-php"> DB::table("clicks") ->select("id" ,DB::raw("(COUNT(*)) as total_click")) ->orderBy('created_at') ->groupBy(DB::raw("MONTH(created_at)")) ->get(); </pre>

By Hardik Savani | June 20, 2016 | | 13339 Viewer | Category : Laravel
READ MORE

How to group by multiple columns in Laravel Query Builder?

Sometimes we may require to add group by with multiple columns, if we have mysql query then we can do it easily by using sql query. But if you want to give multiple columns in groupBy() of Laravel Query Builder then you can give by comma separated values as bellow example. <strong>Example:</strong> <pre class="prettyprint lang-php"> $data = DB::table("items_count") ->select( 'items_count.*' ,DB::raw("SUM(items_count.quantity) as total_quantity")) ->groupBy('items_count.id_item','items_count.id_cat') ->get(); print_r($data); </pre>

By Hardik Savani | June 12, 2016 | | 10479 Viewer | Category : Laravel
READ MORE

    Laravel 5 - Paypal Payment Integration example using netshell/paypal package from scratch

    Laravel 5 - Paypal Payment Integration example using netshell/paypal package from scratch

    Open Post

    Laravel 5 Instagram API tutorial with example

    Laravel 5 Instagram API tutorial with example

    Open Post

    Laravel 5 amazon s3 file upload tutorial - Part 2

    Laravel 5 amazon s3 file upload tutorial - Part 2

    Open Post

    laravel 5.4 New Feature - Add eloquent whereKey method

    laravel 5.4 New Feature - Add eloquent whereKey method

    Open Post

    Laravel - How to search with comma separated values using Query Builder ?

    Laravel - How to search with comma separated values using Query Builder ?

    Open Post

    How to create ban/revoke user functionality in Laravel 5 example ?

    How to create ban/revoke user functionality in Laravel 5 example ?

    Open Post