Monday, 15 July 2013

laravel - How to set multiple boolean mutators -


I am using Laravel 4 and I have a model with Boolean attributes.

I'm setting the setter for each of them

  set the public function ISRmot attribute ($ value) {$ this- & gt; Attributes ['isRemote'] =! ! $ Value; }  

And such a singer

  public function getIsRemoteAttribute ($ value) {Return !! $ This- & gt; ['IsRemote'] explains responsible; }  

Is there an abstract way that I am not personally setting 12+ mutators?

I think you can override like the setAttribute method:

  Public function setActivate ($ key, $ value) {if (in_array ($ key, 'abstract_keys')) {$ this- & gt; Features [$ of] = $ $ $ value; } Other {Parents :: Set properties ($ key, $ value); }}  

same getAttribute .


No comments:

Post a Comment