Htmlspecialchars() Expects Parameter 1 to Be String Array Given

Laravel - htmlspecialchars() expects parameter 1 to be string, object given

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

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

Based on your comment and edits, it seems like you have a value that is in the form of an array so you could try to print it as string using {{ is_array($value2) ? json_encode($value2) : $value2 }}

Laravel htmlspecialchars() expects parameter 1 to be string, object given in my project?

Just change the array key from message to messages in your controller like below:

$data = array(
'messages' => $request->message
);

and also in the blade print it as {{$messages}}

A $message variable is always passed to e-mail views, and allows
the inline embedding of attachments. So, it is best to avoid passing a
message variable in your view payload.

Check the note in this link: http://laravel.com/docs/5.0/mail#basic-usage

Laravel: htmlspecialchars() expects parameter 1 to be string, with anchor tag text?

The error is saying that __('Login') is not a string. This means that it likely is an array of translation keys, as __() by default returns a string (the passed parameter) if the translation is not available.

Inside of resources/lang/{lang}, there is a file called login.php:

return [
'login' => 'Login',
'register' => 'Register'
];

To access this translation, you need to use the correct syntax:

<li class="nav-item"><a class="nav-link" href="{{ route('login') }}">{{ __('login.login') }}</a></li>
<li class="nav-item"><a class="nav-link" href="{{ route('register') }}">{{ __('login.register') }}</a></li>

The string passed to the __() function should first specify the file, followed by any number of keys (as nested arrays are valid). In both cases, login is the file, followed by the keys login and register.

This structure should be duplicated in all resources/lang/{lang}/login.php files, or the default locale (in most cases en) will be used.

The full documentation can be found here: https://laravel.com/docs/7.x/localization

htmlspecialchars expects parameter 1 to be string, array given

If $post->loot->content contains [{"Item":2}]

It is an array of objects so, your $amount is the whole {"Item":2}, not 2.

so the loop can be something like:

@foreach ($post->loot->content as $id=>$json)
@php
$obj =json_decode($json, true)
@endphp
@foreach ($obj as $key=>$val)
<div class="item">
<i class="fab fa-cuttlefish"></i>
<div class="text">{{ $key }} <b>x{{ $val }}</b></div>
</div>
@endforeach
@endforeach

Not sure what you need but maybe you can swap

 <div class="text">{{ $key }} <b>x{{ $val }}</b></div>

with

   <div class="text">{{ $id }} <b>x{{ $val }}</b></div>

If you need the index of the whole object in the list instead of the attribute's obj key.

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

Try this one , you need to use @json()

<script type="text/javascript">

let checkInn = @json($array);
// var checkInn = ["10-10-2021","10-10-2021"];
$('.datepicker').datepicker({
format: 'mm/dd/yyyy',
beforeShowDay: function(date){
dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
if(checkInn.indexOf(dmy) != -1){
return false;
}
else{
return true;
}
}
});
</script>


Related Topics



Leave a reply



Submit