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

[6.x] FindBy added #30442

Closed
wants to merge 2 commits into from
Closed

[6.x] FindBy added #30442

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 28, 2019

Sometimes the find() function it's not enough, for example, we don't have the id, but have the email of the user to find, it's can be easily use findBy('email', '=', 'taylor@laravel.com') or findBy('email', 'like', '%@laravel.com%'), this can be done with where('email', '=', 'taylor@laravel.com')->first(), but, like the find() function, using that function will be to more productivity and will be more easily to find one user with some characteristic.

@JosephSilber
Copy link
Member

Noe that where works without an operator. If we are indeed to add a findBy method, it should also work without providing an operator.

@ghost
Copy link
Author

ghost commented Oct 28, 2019

Fixed

@Miguel-Serejo
Copy link

Collections have a method named firstWhere with the same syntax. Should this method have the same name for consistency?

return;
}

if (count($args) == 2) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, you should change == to === and same with line 371

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be changed, but I don't think it matters in this case

@netpok
Copy link
Contributor

netpok commented Oct 28, 2019

If this is merged it would be nice to have have it like the dynamic wheres.

Example:

User::findByName('Joe');

@samdharris
Copy link

Since you've added findBy, is it worth also adding findByOrFail?

@deleugpn
Copy link
Contributor

I'm guessing you're gonna have to write some tests if this is were to be merged.

@taylorotwell
Copy link
Member

I think you can just use where and first.

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.

7 participants