Say I have a Foo model and I mutate the getter attribute, for example:
Foo
class Foo extends Model { protected $table = 'foo'; public function getSomeBarAttribute($value) { return some_function($value); } }
Is there a way to access the original attribute value, pre-mutation?
The method you are looking for is getOriginal . To get the original value you can use:
$this->getOriginal('some_bar');
The model defines this var:
/** * The model attribute original state. * * @var array */ protected $original = array();
It is protected, so you must add a function to get the initial values.
(not verified)
$currentSomeBar = $foo->some_bar $oldFoo = new Foo($foo->getOriginal()); $oldSomeBar = $oldFoo->some_bar;