Closed sharifzadesina closed 2 years ago
Heya, thanks for reporting.
We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as separate commits on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
laravel new bug-report --github="--public"
Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.
Thanks!
Hello, This was a simple bug, I don't know why I had to create a new repo just for it. Anyways, here you go: https://github.com/sharifzadesina/bug-report
Please NOTE: you need to connect to a working DB, run the migrations, and add a balance
record to the database, then if you visit the welcome page you will see the error. (GMP extension is required because I am using it for custom cast)
Please add the code to create a balance record in order to reproduce the bug.
Hello,
Added DB config and seed to create the record in the database. so you can reproduce the error by running php artisan migrate --seed
and then visiting welcome page.
@driesvints any updates on this?
Thanks, I managed to send in a fix for this.
Description:
It is not possible to cast database attributes to objects using custom cast classes and then convert them to an array.
Steps To Reproduce:
Models class:
and our custom cast class:
The code:
The error that happens:
The reason is obvious, here: HasAttributes.php#L285 we first cast the
amount
attribute to GMP class using custom cast, then inside the nextif
statements (HasAttributes.php#L292, HasAttributes.php#L296, HasAttributes.php#L306 and HasAttributes.php#L933) we try to convert it to boolean, so the error happens. The solution is to try to check the$attributes[$key]
by not converting it to boolean implicitly.