Hi @xtremer360!
I didn't test this answer but could you please try:
$model->getOriginal('foo')
It depends on your Laravel version: https://laravel.com/docs/7.x/upgrade
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I need to figure out a way to unit test that a user has a status property on the model. With this model, I have a custom enum cast object coming from the package listed below. Currently, my test fails at the creation of the user object. The reason being is that it is looking for a value of example as a valid enum valid. Since there is not then it errors. What
I want to do is being to add to the test to have it ignore that specific cast for the purpose of this test. How is that possible?
https://github.com/mad-web/laravel-enum
Error given from test.
UnexpectedValueException: Value 'example' is not part of the enum App\Enums\UserStatus
App\Models\User.php
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'status' => Status::class,
];
tests/Unit/Models/UserTest.php
public function a_user_has_a_status()
{
$user = new User(['status' => 'example']);
$this->assertEquals('example', $user->getRawOriginal('status'));
}
@xtremer360 you can use setRawAttributes which should ignore casting:
$user = new User();
$user->setRawAttributes(['status' => 'example'], true);
$this->assertEquals('example', $user->getOriginal('status'));
https://github.com/illuminate/database/blob/master/Eloquent/Concerns/HasAttributes.php#L1136
Please or to participate in this conversation.