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

TutsPlus.com:
Eloquent Mutators and Accessors in Laravel
Mar 02, 2018 @ 18:20:57

On the TutsPlus.com site they've posted a tutorial for the Laravel users (well, Eloquent users) out there showing the use of mutators and accessors in this ORM package.

In this article, we'll go through mutators and accessors of the Eloquent ORM in the Laravel web framework. After the introduction, we'll go through a handful of examples to understand these concepts.

In Laravel, mutators and accessors allow you to alter data before it's saved to and fetched from a database. To be specific, the mutator allows you to alter data before it's saved to a database. On the other hand, the accessor allows you to alter data after it's fetched from a database. In fact, the Laravel model is the central place where you can create mutator and accessor methods. And of course, it's nice to have all your modifications in a single place rather than scattered over different places.

The tutorial starts with the creation of a simple "Post" model to use in the examples via the artisan command. It also includes the full code to flesh out the class to define a mutator and accessor for the "name" property. It then talks through what these two methods do and how they're called automatically when the property is accessed/updated. It's then put to use in a controller showing each of them in use to work with the published_at date value.

tagged: laravel eloquent tutorial mutator accessor controller model

Link: https://code.tutsplus.com/tutorials/eloquent-mutators-and-accessors-in-laravel--cms-30312

North Meets South Podcast:
Model accessors, style guides, and Nomads
Jan 30, 2018 @ 15:43:15

The North Meets South podcast, with hosts and PHP community members Jacob Bennett and Michael Dyrynda, has posted its latest episode - Episode #39: Model accessors, style guides, and Nomads.

Jake and Michael return for 2018 and discuss model accessors for relationships, documenting style guides, shared database migrations, and more!

Other topics mentioned in this episode include the Vagabond library, the Pusher service and the Laracon AU conference happening later in 2018 in Sydney, Australia.

You can listen to this latest show either using the in-page audio player or by downloading the mp3 for listening at your leisure. If you enjoy the show, be sure to subscribe to their feed and follow them on Twitter for the latest updates when new shows are released.

tagged: northmeetssouth podcast ep39 model accessor styleguide nomad jacobbennett michaeldyrynda

Link: http://www.northmeetssouth.audio/39

DevShed:
Using Subclasses and Accessors with Member Visibility to Protect PHP 5 Class Data
Jun 05, 2008 @ 12:50:08

DevShed has posted the latest in their series of tutorials covering the scoping keywords in PHP5 (public, private and protected). In this latest edition they work with private values from a parent class.

In the last article, I explained how to work with a couple of private properties that partially comprised the API of a basic class, which is useful for saving simple strings to a specified text file.

This part builds on this previous example but changes up the subclass (an instance of DataSaver) to use what they call an "accessor" - a function in the parent that returns the private variable/contstant's current value when called.

tagged: visibility php5 class privat public protected variable accessor

Link:


Trending Topics: