zyxxyzyxz
1 month ago

htmlspecialchars() expects parameter 1 to be string, array given

Posted 1 month ago by zyxxyzyxz

This error is incredibly annoying and the lack of actual information about it is ridiculous for a framework as large as Laravel.

I have a serialized json string in my database, and I'm trying to loop over it with a foreach in a blade template. I cast it inside my model to be an array.

No funny business, no really obscure functionality, this is incredibly basic and the fact that it's providing such a vague error message is pretty appalling.

How exactly can I go about fixing this because from EVERYTHING I've tried, nothing has worked.

  • Tried just normally looping over, gives the same error.
  • Tried casting it to an array, gives the same error.
  • Tried using the {!! !!} syntax, gives the same error.
  • Tried json_decode, gives the same error.

But if I just output the thing by itself, e.g. $model->jsonAttribute it outputs the full string fine???

I do not understand what the issue is. Hopefully someone can help.

Please sign in or create an account to participate in this conversation.