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
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 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 }}
Related Topics
How to Check If a Video Exists on Youtube, Using PHP
Setting Value of a HTML Form Textarea
How to Override Trait Function and Call It from the Overridden Function
Save Current Page as HTML to Server
How to Remove Blank Lines from Text in PHP
Is There Garbage Collection in PHP
Get MySQL Database Output via PHP to Xml
How Does the "&" Operator Work in a PHP Function
Understanding PHP & (Ampersand, Bitwise And) Operator
What Can Use for Datetime::Diff() for PHP 5.2
Traits in PHP - Any Real World Examples/Best Practices
How to Efficiently Find the Closest Locations Nearby a Given Location
How to Generate a Random Key Within PHP
Uncaught Reflectionexception: Class Log Does Not Exist Laravel 5.2