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

[5.4] Pass the condition value to "when" #18419

Merged
merged 1 commit into from Mar 19, 2017

Conversation

Projects
None yet
5 participants
@JosephSilber
Contributor

JosephSilber commented Mar 19, 2017

So that this:

$role = $request->input('role');

$users = User::when($role, function ($query) use ($role) {
    return $query->where('role_id', $role);
})->get();

becomes this:

$users = User::when($request->input('role'), function ($query, $role) {
    return $query->where('role_id', $role);
})->get();

@taylorotwell taylorotwell merged commit 36b2550 into laravel:5.4 Mar 19, 2017

2 checks passed

continuous-integration/styleci/pr The StyleCI analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@taylorotwell

This comment has been minimized.

Show comment
Hide comment
@taylorotwell

taylorotwell Mar 19, 2017

Member

Kinda clever.

Member

taylorotwell commented Mar 19, 2017

Kinda clever.

@JosephSilber JosephSilber deleted the JosephSilber:pass-when-condition branch Mar 19, 2017

@CristianLlanos

This comment has been minimized.

Show comment
Hide comment
@CristianLlanos

CristianLlanos Mar 20, 2017

Cool! Thanks 👍

CristianLlanos commented Mar 20, 2017

Cool! Thanks 👍

@juukie

This comment has been minimized.

Show comment
Hide comment
@juukie

juukie Mar 22, 2017

Contributor

Love it! Really laravelish

Contributor

juukie commented Mar 22, 2017

Love it! Really laravelish

@Ilyes512

This comment has been minimized.

Show comment
Hide comment
@Ilyes512

Ilyes512 Oct 22, 2017

This should have been added to the documentation. Came here through http://laraveldaily.com/less-know-way-conditional-queries/?utm_content=buffer39804&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer I am on my phone now. If I get time later I will make a PR to the docs.

Ilyes512 commented Oct 22, 2017

This should have been added to the documentation. Came here through http://laraveldaily.com/less-know-way-conditional-queries/?utm_content=buffer39804&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer I am on my phone now. If I get time later I will make a PR to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment