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

Laravel News:
Laravel 5.5 Pivot Casting
Jul 06, 2017 @ 09:15:36

On the Laravel News site there's a new post about a feature in the v5.5 release of the popular framework: pivot casting.

A new addition to Laravel 5.5 will add support for pivot table casts when inserting & updating data on an intermediate table model.

Currently, the $casts you set on a traditional model will work in both directions; any model that extends the EloquentModel class will look for a $casts property and convert the specified attributes to a data type when reading and writing.

[...] Now with Laravel 5.5, the $casts property on the EloquentModel and EloquentRelationsPivot classes will behave the same. Laravel will “respect” your casts on both, whether you’re reading, inserting or updating data.

tagged: laravel pivot casting feature insert update

Link: https://laravel-news.com/laravel-5-5-pivot-casting

Gonzalo Ayuso's Blog:
Pivot tables in PHP
Jan 25, 2010 @ 08:45:51

In this new post today Gonzalo Ayuso shows how to make "pivot tables" (at least the concept) in a PHP script to modify a data set and transform it into something else.

It's not very difficult to handle pivot tables by hand but the work is always the same: groups by, totals, subtotals, totals per row... Now I want to write a class to pivot tables in PHP with the most common requirements (at least for me).

His examples takes a few rows of records from a MySQL result and shows how, with the help of a library he's developed, he can make a few commands and fetch just the data he needs including the column to pivot on. A few more examples are also included.

tagged: pivot table tutorial library group

Link: