Laravel 13.40, released on November 3, introduced a strict flag for the request input casting helpers — integer(), float(), boolean(), and string(). It's a small addition that solves two long-standing pain points: silent coercion of garbage input into zeros and false, and exceptions when the input shape doesn't match expectations.
The Problem These Methods Had
Without strict, the casting methods behave like PHP's built-in type juggling:
$request->integer('count', 5); // ?count=abc123 → 0 (default ignored)
$request->boolean('active'); // ?active=maybe → false (treated as falsy)
$request->string('name'); // ?name[]=chris → throws "Array to string conversion"
The first two cases are especially dangerous because they fail silently. Your pagination defaults to page 1 because abc123 cast to 0. A feature flag reads false because the client sent maybe instead of true. The third case crashes instead of falling back.
What strict: true Changes
Pass strict: true as a named third argument (after the default value):
$perPage = $request->integer('per_page', 25, strict: true);
$archived = $request->boolean('archived', false, strict: true);
$maxPrice = $request->float('max_price', 100.0, strict: true);
$name = $request->string('name', 'guest', strict: true);
With strict mode enabled, each method returns the default whenever the input cannot be cleanly represented as the target type:
| Method | Returns default when input is… |
|---|---|
integer() |
Not a valid integer (decimals, leading zeros, overflow, non-numeric strings, booleans) |
float() |
Not a valid number (commas, non-numeric text, booleans) |
boolean() |
Missing, or not one of 1, true, on, yes, 0, false, off, no |
string() |
Not a string, number, or Stringable (arrays, booleans, null) |
So ?count=abc123 now yields your default of 5, not 0. ?active=maybe yields false (your default), not a coerced false. ?name[]=chris yields 'guest', not an exception.
Where It Works
The InteractsWithData trait powers all of these, so strict is available anywhere that trait is used:
Illuminate\Http\Request— controllers, middleware, form requestsIlluminate\Support\Fluent— any fluent data wrapperIlluminate\Support\ValidatedInput— the object returned by$request->safe()Illuminate\Support\UriQueryString— fromUri::query()Illuminate\View\ComponentAttributeBag— Blade component$attributesIlluminate\Console\CommandInput— Artisan$this->input()
This consistency means you can apply the same strictness to query strings, validated input, component attributes, and console commands.
Practical Patterns
Pagination and Limits
$page = $request->integer('page', 1, strict: true);
$perPage = $request->integer('per_page', 25, strict: true);
A malicious or buggy client sending ?page=9999999999 or ?per_page=abc gets the safe default instead of an integer overflow or a zero that breaks your paginator.
Feature Toggles and Filters
$showArchived = $request->boolean('archived', false, strict: true);
$sortDir = $request->string('dir', 'asc', strict: true);
Only explicit true/false values flip the flag. Typos like ?archived=yesplease fall back to your default.
Price and Measurement Inputs
$minPrice = $request->float('min_price', 0.0, strict: true);
$maxPrice = $request->float('max_price', 10000.0, strict: true);
Comma-separated thousands (1,000.50) are rejected — use validation if you need to accept localized formats.
Blade Component Attributes
<!-- Component -->
<input type="text" {{ $attributes->merge(['maxlength' => $attributes->integer('maxlength', 255, strict: true)]) }} />
Invalid maxlength values from parent components fall back safely instead of throwing.
Console Commands
$count = $this->input('count', 10, strict: true);
Typos in scheduled or manually invoked commands behave predictably.
Strict vs. Validation
The documentation is clear: strict casting is not a replacement for validation. Use it for optional parameters with sensible fallbacks — pagination, sorting, display toggles, filter defaults. For required fields where bad input represents a user error, use validation rules:
// Good: optional filter with default
$status = $request->string('status', 'all', strict: true);
// Good: required field, validated
$request->validate(['email' => 'required|email']);
$email = $request->string('email'); // validation already guarantees it's a valid email
Validation gives you localized error messages, custom rules, and the full validator ecosystem. Strict casting gives you a one-liner for "give me this type or give me my default."
Lazy Defaults
The default argument accepts a closure, which is only evaluated when needed:
$perPage = $request->integer('per_page', fn () => config('app.default_per_page'), strict: true);
This avoids hitting config or the database on every request when the input is valid.
Returning null Instead of a Default
Pass null as the default to get null back for invalid or missing input:
$page = $request->integer('page', null, strict: true);
// ?page=abc → null
// ?page=2 → 2
// missing → null
This is useful when you need to distinguish "not provided" from "provided but invalid" — both yield null, but you can combine with $request->has('page') if the distinction matters.
What About array(), date(), enum()?
The strict flag is currently only implemented for string(), boolean(), integer(), and float(). The other casting methods (array(), date(), interval(), enum()) keep their existing behavior. If you need strictness there, validate explicitly.
Migration Notes
- No breaking changes —
strictdefaults tofalse, preserving existing behavior. - Opt-in per call — you can enable it only where it matters.
- Future default? — The PR author (Chris Morrell) noted they'd like to see strict become the default in Laravel 14. If you adopt it now, you'll be ahead of that shift.
When to Reach for It
I reach for strict: true on almost every optional query parameter that drives pagination, sorting, or filtering. The one-liner eliminates a whole class of "garbage in, confusing default out" bugs without the ceremony of a form request for simple cases.
For required fields, complex rules, or anywhere you need to tell the user why their input was rejected, validation remains the right tool. But for the vast majority of "give me an int or give me 25" scenarios, strict: true is now the cleanest answer.
Sources
- Laravel 13.40 release notes — https://laravel-news.com/laravel-13-40-0
- Laravel News: Strict Request Input Casting in Laravel — https://laravel-news.com/laravel-strict-request-input
- GitHub PR #62254 (Chris Morrell) — https://github.com/laravel/framework/pull/62254