0

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.

2
  • Check you data once again ? like for $setfield->code ? Commented Aug 1, 2018 at 5:44
  • i used $setfield->code to make a reference like code = settings id.. Commented Aug 1, 2018 at 6:27

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

0

There is an array anywhere in one of your Blade {{}}, please check them.

Read: https://laravel.com/docs/5.6/blade#displaying-data

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.