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

[8.x] auto handle Jsonable values passed to castAsJson() #34392

Merged
merged 1 commit into from
Sep 17, 2020

Conversation

browner12
Copy link
Contributor

My most common use case for using the castAsJson() method is for fields I have cast as Collections on my Model.

$this->assertDatabaseHas('users', [
    'name' => $user->name,
    'email' => $user->email,
    'nicknames' => $this->castAsJson($user->nicknames->toJson()),
];

With this change, the toJson() method will be called for the user automatically if the value is a Jsonable object.

`Jsonable` objects can be passed in without having to manually call `toJson()`
@taylorotwell taylorotwell merged commit 58dc491 into laravel:8.x Sep 17, 2020
@browner12 browner12 deleted the json-assertions branch February 14, 2021 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants