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

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

Merged
merged 1 commit into from
Jan 17, 2023

Conversation

erikgaal
Copy link
Contributor

@erikgaal erikgaal commented Jan 17, 2023

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