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

No way to check for attribute existence in Eloquent Strict Mode #44746

Closed
levu42 opened this issue Oct 26, 2022 · 3 comments
Closed

No way to check for attribute existence in Eloquent Strict Mode #44746

levu42 opened this issue Oct 26, 2022 · 3 comments

Comments

@levu42
Copy link
Contributor

levu42 commented Oct 26, 2022

  • Laravel Version: 9.35.1
  • PHP Version: 8.1.11

Description:

Imagine a conditional loading of a count in an Eloquent query:

if ($bool) $query = $query->withCount('foo');

Then I want to check in blade whether the count is loaded or not, but in the new Eloquent strict mode, all options I tested threw a MissingAttributeException:

@if($model->foo_count)
@if(isset($model->foo_count))

And some years and Laravel versions back there was a decision made against a hasAttribute method on the HasAttributes trait.

I think this should be reconsidered now, either fixing it so that you can check with isset on the existence of attributes, or include a hasAttribute method.

@driesvints
Copy link
Member

Please see #44717

@levu42
Copy link
Contributor Author

levu42 commented Oct 26, 2022

@driesvints thank you, didn't notice that one :)

@royduin
Copy link
Contributor

royduin commented Jun 25, 2024

It's added in Laravel 11.3: #50909

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

No branches or pull requests

3 participants