-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add cast support #2257
Add cast support #2257
Conversation
Hello, Can you please add a tests? Thanks! |
@divine @Christophvh I really need this feature merged ASAP, I've created an issue regarding this which is likely related and after manually taking the small |
@sts-ryan-holton honestly, probably never. |
@divine how can I get this into my project? It's just a few lines of code and seems to work for me |
It's just two lines without a test that could break any application. How you can get into this project? Well, it's currently in stale mode as I can't merge and release PRs that were created back in March. Thanks! |
Hi @sts-ryan-holton , could you try to add some tests ? You can open a new PR |
I guess it is fixed and this issue no longer exists. If it still exists, please let me know how I can produce it. |
Ran into this today and still isn't working. Pulling a row of data from a csv file and simply running an updateOrCreate() on the model. The subject_id and subject_expeditionId are still entered into the document as strings.
Handling it by adding mutators in my models for every place I need it. For example:
|
@rbruhn can you please create a new issue? I just ran a quick test and it worked just fine. A small test case would help us tremendously. You can use some other tests in I'm closing this pull request as |
I did a few quick tests of my own. They come back correct, (assertIsInt() and assertIsString()) but still stored in the database incorrectly. I believe the test results are showing the getAttribute but not setting correctly before inserting in the database. |
@alcaeus I was checking this problem a couple of days ago. It's really not working. As mentioned in #2393, if you don't cast your values before storing them in the DB, they will be stored as their original data type. To produce this issue, you can test public function testCastingAttributes(): void {
Birthday::truncate();
Birthday::query()->create(['name' => 'Hans','age' => '1']);
self::assertIsBool(Birthday::query()->first()->age); // pass
self::assertIsBool(DB::collection('birthday')->first()['age']); // fail
}
But with this PR, it's working fine. |
Fixes #2199 , #1580