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.
ErrorException: Undefined array key "name"Undefined array key 0Undefined index: nameUndefined offset: 1ErrorException Undefined array key 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
- Use
$data['x'] ?? nullorArr::get() - Use
$request->input()/$request->validated() - Validate required keys first
Detailed fix by platform
Laravel
$name = data_get($payload, 'user.name', 'Guest');
How to diagnose
- Key — Present in the array?
- Source — Request, config, API?
- 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:
Similar errors
- 403 This action is unauthorized Laravel: Illuminate\Auth\Access\AuthorizationException: This action is unauthorized.
- Array offset on null Warning: Trying to access array offset on value of type null
- Attempt to read property "x" on null Laravel/PHP 8: ErrorException: Attempt to read property "name" on null
Most viewed in Laravel
- MassAssignmentException Laravel: Illuminate\Database\Eloquent\MassAssignmentException: Add [x] to fillable property to allow mass assignment
- The GET method is not supported for route Laravel: The GET method is not supported for route x. Supported methods: POST (MethodNotAllowedHttpException)
- Route [login] not defined Laravel: Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 4 Nov 2026