Back to Error Center
htmlspecialchars() expects parameter 1 to be string
Error Message
htmlspecialchars(): Argument #1 ($string) must be of type string, array given
Cause
Passing an array to a Blade {{ }} expression that expects a string. Usually happens when a variable is an array but Blade tries to escape it.
Solution
Access the specific array key in the Blade template. Use @json() for arrays. Debug the variable to understand its structure.
Code Example
Fix
// Wrong - $data might be an array
{{ $data }}
// Right - access specific key
{{ $data['name'] }}
// Or check if it's an array
@if(is_array($data))
@json($data)
@else
{{ $data }}
@endif
// Debug the variable
@dump($data)
Debugging Steps
- Use @dump() to inspect the variable
- Check what the variable actually contains
- Access the specific array key or index
- Verify the controller passes the correct data to the view
Prevention
Always pass the correct data type to views. Use @json() for arrays. Validate data in the controller before passing to the view.