close

[Solved] Laravel – htmlspecialchars() expects parameter 1 to be string, object given

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Laravel – htmlspecialchars() expects parameter 1 to be string, object given in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Laravel – htmlspecialchars() expects parameter 1 to be string, object given Error Occurs?

Today I get the following error Laravel – htmlspecialchars() expects parameter 1 to be string, object given in php.

How To Solve Laravel – htmlspecialchars() expects parameter 1 to be string, object given Error ?

  1. How To Solve Laravel – htmlspecialchars() expects parameter 1 to be string, object given Error ?

    To Solve Laravel – htmlspecialchars() expects parameter 1 to be string, object given Error But best way in this case use the json_encode method in your blade and json_decode in controller.

  2. To Solve Laravel – htmlspecialchars() expects parameter 1 to be string, object given Error

    To Solve Laravel – htmlspecialchars() expects parameter 1 to be string, object given Error But best way in this case use the json_encode method in your blade and json_decode in controller.

Solution 1

When you use a blade echo {{ $data }} it will automatically escape the output. It can only escape strings. In your data $data->ac is an array and $data is an object, neither of which can be echoed as is. You need to be more specific of how the data should be outputted. What exactly that looks like entirely depends on what you’re trying to accomplish. For example to display the link you would need to do {{ $data->ac[0][0]['url'] }} (not sure why you have two nested arrays but I’m just following your data structure).

@foreach($data->ac['0'] as $link)
    <a href="{{ $link['url'] }}">This is a link</a>
@endforeach

Solution 2

You could use serialize

<input type="hidden" name="quotation[]" value="{{serialize($quotation)}}">

But best way in this case use the json_encode method in your blade and json_decode in controller.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment