jeudi 3 novembre 2016

Magic gets and sets for Laravel 5

I know there exists the magic gets and sets in PHP to each attribute of a class:

 public function __get( $key ){
   return $this->values[ $key ]; 
}

public function __set( $key, $value )
{
    $this->values[ $key ] = $value;
}

However, I do not know how to use it with Laravel. I noted that Laravel considers only not null fields (according to the migration) to execute the __get and __set. I want to apply a mask to some fields, so I tried:

public function __get($key)  {
   if($key == 'note1')
     return $this->maskFloat($this->attributes[$attr]);    
 }

But there is no 'note1' field because it is nullable in the migration.

Any help. please?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire