-
Notifications
You must be signed in to change notification settings - Fork 11k
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 hasAttribute() to Eloquent/Model #22249
Conversation
This PR adds the `hasAttribute()` method to check, if a given attribute exist in this model
I would just suggest using isset($model->key). |
@taylorotwell it returns |
Actually, i think, |
@taylorotwell can you please re-open this PR and rethink it? |
see this example here: // let $user be a User model
$user->name = null;
dd(isset($user->name)); // false, even it is set!
dd($user->hasAttribute('name')); // true, even it is null So i think, the |
@johannesschobel Yes. That's what I write about. I think you should make another PR with this description because Taylor doesn't look on closed PRs. |
Need the same, and totally agree with @johannesschobel
I left a petition on change.org for @taylorotwell to merge this. |
It's added in Laravel 11.3: #50909 |
@royduin it's still wrong because it will return true just because you have a cast or a mutator, which will never indicate that the attribute actually exists. |
This PR adds the
hasAttribute()
method toEloquent/Model
in order to check, if a given attribute exist in this model