Laravel Defining a Mutator


Example

class User extends Model  
{
    public function setPasswordAttribute($password)
    {
        $this->attributes['password'] = bcrypt($password);
    } 
    ... 
}

Above code does "bcrypting" each time password property is set.

$user = $users->first();
$user->password = 'white rabbit'; //laravel calls mutator on background
$user->save(); // password is bcrypted and one does not need to call bcrypt('white rabbit')