How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How Laravel’s old() Helper Works (and Why It Sometimes Doesn’t)
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • 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.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

CSS page break for printing shown in a print preview layout
Web Development

CSS Page Break for Printing: How to Split a Web Page Into Multiple Printed Pages

6 Min Read
Laravel get config variable — config() helper and Config facade resolving dotted keys
Web Development

How to Get Config Variables in Laravel

7 Min Read
Replace jQuery .each with vanilla JavaScript loops
Web Development

How to Replace jQuery’s .each() with Vanilla JavaScript

4 Min Read
Laravel migration adding two new columns to an existing transactions table
Web Development

How to Add New Columns to an Existing Table in Laravel Migration

5 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • 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?