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 #15421

Closed
wants to merge 120 commits into from

Conversation

tomschlick
Copy link
Contributor

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();

Kristoffer Alfheim and others added 30 commits August 20, 2016 16:23
…avel#15167)

In instances where your queue driver goes away (network connectivity,
database locks, jobs table doesn’t exist, etc), exceptions are
generated but never caught by the `pop` method.

As a result, `sleep` is never called and these exceptions are spewed to
`laravel.log` until either somebody notices, the driver returns, or the
log file fills the disk entirely/you tank your <remote bug tracking
service> quota for the month.
Fixes the model name variables (from lower case to camel case) when generating a policy class based on a model.
…ks-consistency

[5.3] Fix some phpdoc inconsistencies
taylorotwell and others added 13 commits September 9, 2016 11:33
…aravel#15380)

* Changed startsWith and endsWith to use substr (non mbstring), this is ok here because it doesn't
matter whether it's multi-byte unicode chars or not, just that the same number of bytes match at
the start or the end.

The performance of the existing methods becomes increasingly slow with larger strings due to
 mbstring functions.

* removed spacing between parenthesis
…avel#15397)

* Add test to prevent a potential regression

* Restore support for non-string needle

* Code unification
allows you to specify a default in the case that the when() $value is false
@themsaid themsaid changed the base branch from 5.3 to master September 14, 2016 09:34
@themsaid themsaid changed the base branch from master to 5.3 September 14, 2016 09:35
@themsaid
Copy link
Member

Submit to master?

@themsaid themsaid closed this Sep 14, 2016
@themsaid
Copy link
Member

@tomschlick thank you but please submit to master since it's a breaking change.

@tomschlick
Copy link
Contributor Author

I can switch it if necessary... was just following what I have done in the past and what is done in the existing pull requests.

If you re-open the pull request I can change the branch on it through the edit button... Github enabled that a few weeks ago.

This also is not breaking...

@themsaid themsaid reopened this Sep 14, 2016
@tomschlick tomschlick changed the base branch from 5.3 to master September 14, 2016 09:39
@themsaid themsaid closed this Sep 14, 2016
@tomschlick tomschlick changed the base branch from master to 5.3 September 14, 2016 09:40
@tomschlick
Copy link
Contributor Author

Ugh I guess that doesn't work that well. I'll re-open on master.

@themsaid
Copy link
Member

@tomschlick I guess it's better that you open a new PR to master, this switching thing on GitHub sometimes acts weird, and till this point I was too lazy to understand why it acts that way :)

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.