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

Make PendingRequest Conditionable #40762

Merged
merged 1 commit into from
Feb 2, 2022
Merged

Make PendingRequest Conditionable #40762

merged 1 commit into from
Feb 2, 2022

Conversation

phillipfickl
Copy link
Contributor

This pull request makes PendingRequest Conditionable.

It will let you use when() and unless() to make the code a bit more readable.
Example where I would have used it:

$this->http = Http::withBasicAuth(
            $username,
            $password
        );

        if (app()->environment('local')) {
            $this->http->withoutVerifying();
        }
        
        if ($baseUrl !== null) {
            $this->http->baseUrl($baseUrl);
        }

becomes

$this->http = Http::withBasicAuth(
            $username,
            $password
        )->when(app()->environment('local'), function (PendingRequest $request) {
            $request->withoutVerifying();
        })->when($baseUrl !== null, function (PendingRequest $request) {
            $request->baseUrl($baseUrl);
        });

@taylorotwell taylorotwell merged commit 442b6d0 into laravel:8.x Feb 2, 2022
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.

2 participants