Request
Request is an immutable value object built once per request, via
Request::capture() in production or Request::fromArrays() in tests.
Input is parsed, never implicitly normalized — normalization only happens where you explicitly ask
for it.
Accessors
$request->method(): string
$request->path(): string
$request->query(string $key, mixed $default = null): mixed
$request->input(string $key, mixed $default = null): mixed
$request->json(?string $key = null, mixed $default = null): mixed // dot-notation key
$request->header(string $name): ?string
$request->cookie(string $name): ?string
$request->file(string $name): ?UploadedFileInterface
$request->ip(): string
$request->userAgent(): ?string
$request->rawBody(): string
$request->all(): array // query + input merged
Reading JSON
$request->json(); // fully decoded body
$request->json('customer.name'); // dot-notation into a decoded object/array
$request->json('customer.name', 'Guest'); // with a default
When the Jsonify middleware ran on this request, json() reads its
pre-parsed data bag. When it didn't, json() lazy-parses the raw body itself with
identical decode settings — the behavior is indistinguishable to the caller either way.
Construction
Request::capture(): self // from PHP superglobals — the production path
Request::fromArrays(query: [], input: [], server: [], cookies: [], files: [], rawBody: ''): self // tests
PSR-7 bridge
$request->toPsr7(): Psr\Http\Message\ServerRequestInterface
Request::fromPsr7(Psr\Http\Message\ServerRequestInterface $psrRequest): static
Next steps
- Request/Response Lifecycle — where
Requestfits end to end. - PSR-7 Bridge — why
toPsr7()/fromPsr7()exist instead of implementing PSR-7 directly. - Response — the other half of every request.