Search code examples
laravellaravel-5eloquentaccessor

Access raw Eloquent mutated attribute value in Laravel 5


Say I have a model Foo and I'm mutating an attribute getter, like so:

class Foo extends Model
{   
    protected $table = 'foo';

    public function getSomeBarAttribute($value)
    {
        return some_function($value);
    }
}

Is there a way to access the attribute's raw value, pre-mutation?


Solution

  • The method you look for is getOriginal. To get the original value you might use:

    $this->getOriginal('some_bar');