Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
larskoole opened this issue Dec 19, 2023 · 1 comment · Fixed by #49480
Closed

Comments

@larskoole
Copy link

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)
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment