Undefined array key Laravel Origin: Application & API Last updated 4 Nov 2026

Laravel/PHP 8: ErrorException: Undefined array key "name" (PHP 8) / Undefined index: name (PHP 7)

Code read an array element whose key isn't present.

Exact message you may see ErrorException: Undefined array key "name"Undefined array key 0Undefined index: nameUndefined offset: 1ErrorException Undefined array key
Seen on: Laravel PHP

Meaning

PHP 8 turned "Undefined index/offset" notices into warnings that Laravel converts to exceptions. Use $arr['x'] ?? 'default', Arr::get($arr, 'x'), isset(), or $request->input('x') which returns null safely. Validate input before reading it.

Common causes

  • Missing request/input key
  • Config or JSON key absent
  • Optional form fields
  • Different data shape from an API
  • Array index beyond the list

⚡ Quick fix

  1. Use $data['x'] ?? null or Arr::get()
  2. Use $request->input() / $request->validated()
  3. Validate required keys first

Detailed fix by platform

Laravel

  1. $name = data_get($payload, 'user.name', 'Guest');

How to diagnose

  1. Key — Present in the array?
  2. Source — Request, config, API?
  3. Default — Null-coalescing?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

403 This action is unauthorized — Laravel: Illuminate\Auth\Access\AuthorizationException: This action is unauthorized. (Laravel)403 This action is un…Array offset on null — Warning: Trying to access array offset on value of type null (PHP)Array offset on nullAttempt to read property "x" on null — Laravel/PHP 8: ErrorException: Attempt to read property "name" on null (Laravel)Attempt to read prope…Command "x" is not defined — Laravel: Symfony\Component\Console\Exception\CommandNotFoundException: Command "make:livewire" is not defined. Did you mean one of these? (Laravel)Command "x" is not de…Laravel: Allowed memory size exhausted (request) — Laravel/PHP: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in vendor/laravel/framework (Laravel)Laravel: Allowed memo…TypeError: Argument #1 must be of type X, Y given — Laravel/PHP: TypeError: App\Services\Mailer::send(): Argument #1 ($user) must be of type App\Models\User, null given (Laravel)TypeError: Argument #…Unable to locate a class or view for component — Laravel: InvalidArgumentException: Unable to locate a class or view for component [alert]. (Laravel)Unable to locate a cl…Undefined array key — Warning: Undefined array key / Undefined index (PHP)Undefined array keyUndefined…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.