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

[5.3] add $default parameter to query builder when() method #15428

Merged
merged 5 commits into from
Sep 14, 2016

Conversation

tomschlick
Copy link
Contributor

Trying this again (old PRS #15422 #15421)

This allows you to specify a default closure to run if the when() $value attribute is false.

I recently found myself creating a sorting / filtering system with defaults that the user could change. Without this you would have to do all kinds of wackiness to clear the previous where() clause on $value being true.

Here is an example of this in action

Time::when($request->has('type'), function ($query) use ($request) {
    return $query->where('type', $request->input('type'));
}, function ($query) {
    return $query->where('type', 1);
})
->get();

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.

None yet

2 participants