Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Christoph Rumpel:
GroupBy multiple levels in Laravel
Jan 29, 2018 @ 15:35:01

In a post to his site Christoph Rumpel shows the Laravel (well, Eloquent) users out there how to use groupBy at multiple levels for customizing and sorting the results of your database queries.

Since Laravel v5.5.29 you can group collections by multiple levels. Let's see what this means and how this works.

The post starts with some of the current functionality, showing how the groupBy could be used before with a simple collection to group student data by skill level. It then gets into the new functionality, modifying the example to group by both the skill level and by the "teacher" value. The result is a sorted set of results where the top level is the skill level and, inside of each, the teachers with students under that. The post finishes by "going crazy" and showing the grouping by event more criteria, adding "name" and "email" columns to the list.

tagged: groupby group database multiple level laravel eloquent tutorial

Link: https://christoph-rumpel.com/2018/01/groupby-multiple-levels-in-laravel

Debuggable Blog:
How to Group By in CakePHP's new release Part 2
Jun 17, 2008 @ 15:21:44

In this new post to the Debuggable blog, Tim Koschutki points out the method for using grouping in your CakePHP application's queries (specifically in the new Release 2).

Having promised it in the first post on how to do Group By in CakePHP I worked on an array() version for the group statement in Model::find() calls. So I implemented it.

His code shows the calls to find() the grouped information and accompanying unit test assertEquals calls to check that the results are correct. His examples show a few different ways to accomplish the same thing.

tagged: groupby database query cakephp framework assertequals

Link:

Debuggable Blog:
How to do Group By conditions in Model find() calls in the CakePHP RC1
Jun 12, 2008 @ 13:48:09

On the Debuggable blog, Tim Koschutzki shows how to use grouping in your SQL statements with the find() method calls inside of a Model for an app.

We have to thank Mark Story and wluigi for working on group by conditions for Cake's Model::find() method. Up until now, you would have to add your GROUP BY stuff to string'ed conditions in order to support a group by statement, which could be very ugly.

He has some code included that compares the two methods - the newer of the two applying the 'group' option as a regular condition to the query object.

This functionality is currently only in the the Release Candidate 1 but will be included in the next major release.

tagged: cakephp framework groupby grouping conditional paginate

Link:


Trending Topics: