问题
Already done a research but I don't find the right answer that fit my problem.
error: htmlspecialchars() expects parameter 1 to be string, array given(create.blade)
<div class="an-single-component with-shadow">
<div class="an-component-body">
@foreach($setting as $setfield)
@if($setfield->type === 'smallInteger')
<div class"form-group" style="padding:20px">
<div style="display:inline-block">
<P><input type="hidden" name="set_id[{{$setfield->code}}]" value="{{$setfield->id}}">{{$setfield->display_name}}</P>
</div>
<div class="an-switch-box-wrapper pull-right" style="display:inline-block">
<div class="lcs_wrap">{{ Form::checkbox($setfield->code, '1', true) }}
<div class="lcs_switch lcs_checkbox_switch lcs_on">
<div class="lcs_cursor"></div>
<div class="lcs_label lcs_label_on">ON</div>
<div class="lcs_label lcs_label_off">OFF</div>
</div>
</div>
</div>
</div>
@elseif($setfield->type === 'string')
<div class"form-group" style="padding:20px">
<div style="display:inline-block">
<P><input type="hidden" name="set_id[{{$setfield->code}}]" value="{{$setfield->id}}">{{$setfield->display_name}}</P>
</div>
<div class="an-switch-box-wrapper pull-right" style="display:inline-block">
{!!Form::text($setfield->code,old($setfield->code),['class'=>'form-control','style'=>'width: 100%'])!!}
</div>
</div>
@elseif($setfield->type === 'integer')
<div class"form-group" style="padding:20px">
<div style="display:inline-block">
<P><input type="hidden" name="set_id[{{$setfield->code}}]" value="{{$setfield->id}}">{{$setfield->display_name}}</P>
</div>
<div class="an-switch-box-wrapper pull-right" style="display:inline-block">
{!!Form::text($setfield->code,old($setfield->code),['class'=>'form-control','style'=>'width: 100%'])!!}
</div>
</div>
@elseif($setfield->type === 'date')
<div class"form-group" style="padding:20px">
<div style="display:inline-block">
<P><input type="hidden" name="set_id[{{$setfield->code}}]" value="{{$setfield->id}}">{{$setfield->display_name}}</P>
</div>
<div class="an-switch-box-wrapper pull-right" style="display:inline-block">
{!!Form::date($setfield->code,old($setfield->code),['class'=>'form-control','style'=>'width: 100%'])!!}
</div>
</div>
@endif
@endforeach
</div>
</div> <!-- end .AN-SINGLE-COMPONENT -->
When I do dd($request->all())
I got all the data but when I click submit the error will occur.
回答1:
This is not a Laravel specific error:
in php documents if you see
htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
this function accepts, 2 parameters, first one is a string and second is an optional parameter.
If you have an array of strings to be escaped then use foreach and escape each string
回答2:
There is an array anywhere in one of your Blade {{}}, please check them.
Read: https://laravel.com/docs/5.6/blade#displaying-data
回答3:
You are using Array inside {{}} somewhere. You can only use String inside {{}}.
use {{dd(variable_name)}} to check the variable before you use it inside {{}}. if its an array convert it into String first ( using implode()) ).
implode documentation: http://php.net/manual/en/function.implode.php
blade documentation: https://laravel.com/docs/5.6/blade#displaying-data
来源:https://stackoverflow.com/questions/51625944/htmlspecialchars-expects-parameter-1-to-be-string-array-given-laravel-5-6