Laravel 5 Eloquent attribute casting
Published on by Eric L. Barnes
Jens Segers wrote about the new Eloquent attribute casting and how he has been using it:
For me personally, this will be especially useful when working with boolean values. Boolean values are usually stored as a TINYINT in the database, and when Eloquent fetches the model again, they are returned as a “1” or “0” string. “Luckily” for us, PHP does some type juggling and implicitly converts it to the correct boolean values.
Building rich client side apps with this is really going to be awesome. No more parseInt() or crazy checks to see what data you are getting. I’m a big fan of this feature.
Eric is the creator of Laravel News and has been covering Laravel since 2012.