Laravel 5.3 - HTMLspecialchars() Expects Parameter 1 to Be String

Laravel 5.3 - htmlspecialchars() expects parameter 1 to be string

I think your $user->website is empty/blank.

If you look at the url() helper method, Laravel will return an instance of UrlGenerator if $path is null.

So in your case if $user->website is empty, you'd get UrlGenerator back and thus your error about htmlspecialchars getting an object.

One simple solution would be to wrap your html chunk with a check:

@if($user->website)
<li>
...
</li>
@endif

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

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

{{}} will be converted to echo() by Blade template engine. And you're trying to echo the array as a string.

You may convert it to JSON:

var value = '{{ json_encode($sliderImageDataArray) }}';

If it's a Laravel collection or a model:

var value = '{{ $sliderImageData->toJson() }}';

htmlspecialchars() expects parameter 1 to be string laravel

The second value for textarea() and text() must be a default value, try this:

Form::textarea('desc', '', ['rows'=>'3'

Form::text('name', '', ['class'=>'form-control'

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

OK I finally have an answer for this problem....it seems like something has changed in Laravel 5.3 and if you want to have a name with array like this

{!! Form::label('title', '* Eventname: ', ['class' => 'control-label']) !!}
{!! Form::text('title[]', null, ['class' => 'form-control', 'required') !!}

You must put [0] something in brackets 'indices' like this:

{!! Form::text('title[0]', null, ['class' => 'form-control', 'required') !!}

and then in validation use

title.*

for rule

UPDATE

Because i use dynamic form that can be expanded and new form fields added (optionally) i needed to put [] array notation for a name but actually if you already have hard coded many fields with the same name like item[]
you don't have to put [0] indices inside. The validation will work for them.

The problem comes only if you have a single input field and you put [] array notation along the name for example 'item[]'

this will trigger the error if any validation rule is broken...

htmlentities() expects parameter 1 to be string, object given

The problem is in PagesController inside the Mail::send.

'message' => $request->get('message');

You are using the variable name 'message' and it should be avoided.

Note: 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.

source: http://laravel.com/docs/5.0/mail#basic-usage in the first note.

You might need to change the variable name to be something else.

'bodyMessage' => $request->get('message');

And don't forget the change the variable name in your contact.blade.php as well

<p>
Name: {{ $name }}
</p>

<p>
{{ $email }}
</p>

<p>
{{ $phone }}
</p>

<p>
{{ $bodyMessage }} // This line.
</p>


Related Topics



Leave a reply



Submit