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

Optional should implement __isset #24031

Closed
ghost opened this issue Apr 27, 2018 · 1 comment
Closed

Optional should implement __isset #24031

ghost opened this issue Apr 27, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 27, 2018

  • Laravel Version: 5.6
  • PHP Version: 7.2
  • Database Driver & Version: No Database

Description:

\Illuminate\Support\Optional should implement __isset, there are some cases that maight need this.
For example, I have an Eloquent HasMany relation, say contacts on model User:

<?php
$user = User::find(1);
$hasPhoneNumber = !empty(optional($user->contacts->first())->cellphone);

$user->contacts maight be an empty Collection, so I have to check it by optional helper.
Since the Optional didn't implement __isset, $hasPhoneNumber will always be false.

Steps To Reproduce:

See code above.

@tillkruss
Copy link
Contributor

Feel free to submit a pull request.

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

1 participant