How7oHow7o
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How Laravel’s old() Helper Works (and Why It Sometimes Doesn’t)
Share
Notification Show More
Font ResizerAa
How7oHow7o
Font ResizerAa
  • Tools
  • Prank Screens
  • Learn
  • Blog
Search
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How Laravel’s old() Helper Works (and Why It Sometimes Doesn’t)
Web Development

How Laravel’s old() Helper Works (and Why It Sometimes Doesn’t)

how7o
By how7o
Last updated: May 23, 2026
6 Min Read
Laravel old() helper for repopulating form inputs
SHARE

Laravel’s old() helper repopulates form inputs with the user’s previously submitted values after a validation failure. For edit forms, pass the model’s current value as the second argument so the field shows the database value on first render and the user’s submitted value after validation: {{ old('name', $user->name) }}. If old() returns empty after a manual redirect, the cause is almost always a missing ->withInput().

Contents
  • The pattern for edit forms
  • old() vs old() ?? $value
  • Why old() sometimes returns nothing
  • Array and nested-input fields
  • For <select> and checkboxes
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on Laravel 11. Originally published 2023-03-15, rewritten and updated 2026-05-17. (Merges old posts 195 and 194 — both about the old() helper.)

The pattern for edit forms

<input type="text" name="name" value="{{ old('name', $user->name) }}">
<input type="email" name="email" value="{{ old('email', $user->email) }}">
  • Initial render of the edit form — no old input in the session; old() returns the second argument ($user->name).
  • After a failed submit — Laravel flashed the user’s input back into the session; old() returns that value, preserving whatever they typed (including the typo that failed validation).
Laravel old() — second-arg default, validate auto-flashes, withInput for manual redirects, array fields with dot notation

old() vs old() ?? $value

{{-- Recommended --}}
value="{{ old('name', $user->name) }}"

{{-- Works but slightly less robust --}}
value="{{ old('name') ?? $user->name }}"

The second-argument form is the documented pattern. The ?? variant works in most cases but has edge cases where old() returns empty string instead of null and the fallback doesn’t fire.

Why old() sometimes returns nothing

When you use $request->validate() or a Form Request, Laravel automatically:

  1. Detects validation failure.
  2. Flashes the submitted input into the session.
  3. Redirects back to the previous URL.

If you do this manually, you have to call ->withInput() yourself — otherwise the session is empty and old() finds nothing.

// WRONG — old() returns nothing because no input was flashed
return back()->withErrors(['name' => 'Already taken']);

// RIGHT — input is flashed for old() to read
return back()
    ->withErrors(['name' => 'Already taken'])
    ->withInput();

// Or selectively
return back()
    ->withErrors(['name' => 'Already taken'])
    ->withInput($request->except(['password', 'password_confirmation']));

$request->except([...]) on the manual flash lets you exclude sensitive fields from being flashed back — important for password fields where flashing them back to the form would echo the user’s password in the rendered HTML.

Array and nested-input fields

{{-- For a single field --}}
<input name="user[name]" value="{{ old('user.name', $user->name) }}">

{{-- For multi-row table forms --}}
@foreach ($items as $i => $item)
    <input
        name="items[{{ $i }}][quantity]"
        value="{{ old("items.{$i}.quantity", $item->quantity) }}"
    >
@endforeach

Dot notation reaches into nested arrays in the flashed input. The fallback (second argument) works the same way for nested paths.

For <select> and checkboxes

{{-- Select --}}
<select name="role">
    @foreach (['admin', 'editor', 'viewer'] as $role)
        <option value="{{ $role }}" @selected(old('role', $user->role) === $role)>
            {{ ucfirst($role) }}
        </option>
    @endforeach
</select>

{{-- Checkbox --}}
<input type="checkbox" name="active" value="1"
    @checked(old('active', $user->active))>

@selected and @checked are Blade shortcuts (Laravel 9+) that render the attribute only when the condition is true. They pair cleanly with old().

Frequently asked questions

Where does old() read its values from?

The previous-request’s flashed input — stored in the session under the _old_input key. Laravel automatically flashes input when you call $request->validate() and validation fails, or when you explicitly call ->withInput() on a redirect. If neither happened, the session has nothing flashed and old() returns the default.

Why does old() work on the edit form but not after a manual redirect?

$request->validate() handles the redirect-with-input automatically when validation fails. Custom validation paths don’t — you have to call ->withInput() yourself: return back()->withErrors($errors)->withInput(). Without it, the session is empty on the next render and old() falls back to nothing.

Does the second argument to old() work with array fields?

Yes — old('users.0.name', $user->name) reads from the flashed input’s nested path, falling back to $user->name. Dot-notation works for both reads. For multi-row forms, this is the cleanest way to repopulate after a validation failure without ternary chains.

Is {{ old('x') ?? $value }} the same as {{ old('x', $value) }}?

Almost — but the second argument is the recommended form. old('x', $value) uses Laravel’s built-in default. old('x') ?? $value works too, but old('x') returns an empty string in some flash-not-set edge cases, and ?? only triggers on null — so the fallback doesn’t fire. The two-arg form is consistent.

Related guides

  • How to Validate a Unique Column on Update in Laravel
  • How to Check if Exist in the Database with the Laravel Validator
  • How to Create a Login and Registration System in Laravel

References

Laravel helper old(): laravel.com/docs/helpers#method-old. Validation redirect-with-input: laravel.com/docs/validation#repopulating-forms. @selected / @checked directives: laravel.com/docs/blade#selected.

TAGGED:formsLaravelphpValidation

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Securely hash passwords in PHP with password_hash Securely Hash Passwords in PHP (password_hash, Argon2id)
Next Article Laravel database transactions explained Laravel Database Transactions Explained (DB::transaction vs beginTransaction)
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

You Might Also Like

Laravel unknown column CONCAT fix — DB::raw and selectRaw bypass identifier escaping
Web Development

How to Fix “Unknown column ‘CONCAT'” in Laravel

8 Min Read
Display only the current date in Laravel using Carbon
Web Development

How to Display Only the Current Date in Laravel (Carbon Examples)

4 Min Read
Comment in a .gitignore file with the # character
Web Development

How to Comment in a .gitignore File

4 Min Read
Replace Broken Images Automatically with JavaScript
Web Development

Replace Broken Images Automatically with JavaScript (and jQuery)

5 Min Read
How7oHow7o

Free browser-based tools, prank screens, and step-by-step tech tutorials. No signup, nothing uploaded.

  • Private by design — your files never leave your device
  • Instant — no signup, no install, no waiting
  • Always free — no trials, no watermarks, no paywalls

Tools

  • PDF Editor
  • Image Upscaler
  • JPEG Compressor
  • Password Generator
  • QR Code Generator
  • Video Trimmer
  • See all tools →

Pranks

  • Cracked Screen Prank
  • Fake Blue Screen (BSOD)
  • Fake Disk Format
  • Fake Low Battery
  • Fake Nintendo Switch Update Screen
  • Fake PlayStation Update Screen
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?