Skip to content

Model::preventAccessingMissingAttributes() doesn't fire when needed if cast is defined #49434

Closed
@larskoole

Description

@larskoole

Laravel Version

10.37.4

PHP Version

8.2

Database Driver & Version

No response

Description

When having Model::preventAccessingMissingAttributes() active in theAppServiceProvider.php and there's a model with a cast (in our case boolean) it will not throw an exception when accessing the attribute if it isn't loaded.

When removing the cast it does throw an exception.

Steps To Reproduce

class Test extends Model
{
    protected $fillable = [
        'some_boolean',
    ];

    protected $casts = [
        'some_boolean' => 'boolean',
    ];
}

Test::create(['some_boolean' => true]);

$test = Test::select('id')->first();

$test->some_boolean; (null)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions