Skip to content

[9.x] Add notFound helper to Http Client response#45681

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
erikgaal:patch-http-client-not-found
Jan 17, 2023
Merged

[9.x] Add notFound helper to Http Client response#45681
taylorotwell merged 1 commit into
laravel:9.xfrom
erikgaal:patch-http-client-not-found

Conversation

@erikgaal

@erikgaal erikgaal commented Jan 17, 2023

Copy link
Copy Markdown
Contributor

This PR adds some syntactic sugar to the Http Client Response class.

In a project we had to use the following code to check if a response was 404 Not Found

$response = Http::get('https://laravel.com');

if ($response->status() === 404) {
    doSomething();
}

You could still replace the 404 literal with a constant Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND, but that adds a unnecessary dependency there.

With this PR you can do the following, which is a bit cleaner.

$response = Http::get('https://laravel.com');

if ($response->notFound()) {
    doSomething();
}

@erikgaal erikgaal changed the title [9.x] Add notFound helper to Http Client responses [9.x] Add notFound helper to Http Client response Jan 17, 2023
@taylorotwell
taylorotwell merged commit d064fbc into laravel:9.x Jan 17, 2023
@erikgaal
erikgaal deleted the patch-http-client-not-found branch January 18, 2025 15:11
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