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

[10.x] HasCasts returning false instead of true #46992

Merged
merged 5 commits into from
May 9, 2023
Merged

[10.x] HasCasts returning false instead of true #46992

merged 5 commits into from
May 9, 2023

Conversation

jure-knezovic
Copy link
Contributor

@jure-knezovic jure-knezovic commented May 9, 2023

In current casting implementation, when class is used as a cast type, hasCast is returning false, as it is falling back to else in case class-string is given, which in turn trims it & makes it lowercase. That means f.e. App\Enums\StatusEnum becomes app\enums\statusenum, which in hasCasts function is case-sensitive compared with actual class and is therefore returning false instead of true.

This PR offers a simple fix which checks if provided string is a class instance & if it is, it returns it as is from getCastType function.

Steps to reproduce:

  1. Create model with enum cast
  2. Try calling $model->hasCast('enum',Enum::class) -> expected true, false received

@driesvints driesvints changed the title [10.x]HasCasts returning false instead of true [10.x] HasCasts returning false instead of true May 9, 2023
@taylorotwell taylorotwell merged commit ed5425a into laravel:10.x May 9, 2023
milwad-dev pushed a commit to milwad-dev/framework that referenced this pull request May 12, 2023
* fix: HasCasts returning false when fully qualified class-name was provided as a second parameter

* fix: styling

* fix: Removed unecessary PHP check

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
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.

3 participants