laravel status server code example

Example 1: larvel make http request

// To make requests, you may use the get, post, put, patch, and delete methods
// provided by the Http facade.

use Illuminate\Support\Facades\Http;

$response = Http::get('http://example.com');

// The get method returns an instance of Illuminate\Http\Client\Response,
// which provides a variety of methods that may be used to inspect the response:
$response->body() : string;
$response->json() : array|mixed;
$response->collect() : Illuminate\Support\Collection;
$response->status() : int;
$response->ok() : bool;
$response->successful() : bool;
$response->failed() : bool;
$response->serverError() : bool;
$response->clientError() : bool;
$response->header($header) : string;
$response->headers() : array;

Example 2: laravel resource set status code

use App\User;
use App\Http\Resources\User as UserResource;

Route::get('/user', function () {
    return (new UserResource(User::find(1)))
               ->response()
               ->setStatusCode(200);
});

Tags:

Php Example