Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Bananero's avatar

htmlspecialchars(): Argument #1 ($string) must be of type string, array given

I am trying to edit a form that I am making but it always gives me this error, I am using Laravel 9

model


 class Documento extends Model
{
  use HasFactory;
  protected $fillable = [
    'sigla',
    'nombre',
    'orden',

  ];

  protected $primaryKey = 'idtipodocumento';
} 

controller


public function edit($idtipodocumento)
 {
   $documento = Documento::find($idtipodocumento);
   return view('documentos.editar', compact('documento'));
 }

index view


@foreach ($documentos as $documento)
                                        <tr>
                                            <td style="display: none;">{{ $documento->idtipodocumento }}</td>
                                            <td>{{ $documento->sigla }}</td>
                                            <td>{{ $documento->nombre }}</td>
                                            <td>{{ $documento->orden }}</td>
										 </tr>
    @endforeach

edit view


<div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">
                            {!! Form::model($documento, [
                                'method' => 'PATCH',
                                'route' => ['documentos.update', $documento->idtipodocumento],
                            ]) !!}
                            <div class="row">
                                <div class="col-xs-6 col-sm-6 col-md-6">
                                    <div class="form-group">
                                        <label for="">Sigla*</label>
                                        {!! Form::text('sigla', ['class' => 'form-control']) !!}
                                    </div>
                                </div>

                                <div class="col-xs-6 col-sm-6 col-md-6">
                                    <div class="form-group">
                                        <label for="">Nombre*</label>
                                        {!! Form::text('nombre', ['class' => 'form-control']) !!}
                                    </div>
                                </div>

                                <div class="col-xs-6 col-sm-6 col-md-6">
                                    <div class="form-group">
                                        <label for="">Orden*</label>
                                        {!! Form::number('orden', ['class' => 'form-control']) !!}
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-xs-12 col-sm-12 col-md-12">
                            <button type="submit" class="btn btn-primary">Guardar</button>
                        </div>
                    </div>
                    {!! Form::close() !!}
                </div>

I have already tried in several ways to solve the error but I still can't find it, I appreciate your help, thank you very much

0 likes
13 replies
Sinnbeck's avatar

Please format your code by adding ``` before and after it. Also if you write in English we are more that can help you

1 like
Sinnbeck's avatar

@Bananero Close but the code is still very hard to read. The ``` goes on the line before and after the code, not on the same line

Can you see what line is throwing the error?

1 like
kokoshneta's avatar

What line is throwing the error? If you dd() whatever variable you are outputting on that line, what is the result?

Bananero's avatar

@kokoshneta the error is in the edit view,

‘’’ Form::model($documento, [ 'method' => 'PATCH', 'route' => ['documentos.update', $documento->idtipodocumento], ]) !!}

‘’’

kokoshneta's avatar

@Bananero The Form class was – as far as I can tell – removed in Laravel 5, and you say you’re using Laravel 9, so I’m guessing you’re using some external form package? If so, which one? Or is Form just your own class, with your own models?

In any case, we’d need to see the definition of Form::model(). It looks like that method is returning an array, rather than a string.

kokoshneta's avatar

@Bananero What does dd(Form::model($documento, [ 'method' => 'PATCH', 'route' => ['documentos.update', $documento->idtipodocumento]])) output?

Sinnbeck's avatar

What line is throwing the error? It should show it in the error window.

Bananero's avatar

@Sinnbeck


   function e($value, $doubleEncode = true)

    {

        if ($value instanceof DeferringDisplayableValue) {

            $value = $value->resolveDisplayableValue();

        }



        if ($value instanceof Htmlable) {

            return $value->toHtml();

        }



        if ($value instanceof BackedEnum) {

            $value = $value->value;

        }



        return htmlspecialchars($value ?? '', ENT_QUOTES, 'UTF-8', $doubleEncode);

    }

}

sebaxba's avatar

Could you check in which row in a blade the error appears. It might be some problem with the model but it is hard to guess when we dont know in which line is a problem.

Please or to participate in this conversation.