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

publicado por: Anonymous

Tengo un problema al mandar un consulta en un select me marca el error htmlentities() expects parameter 1 to be string, object given

mi Controlador es la siguiente:

        $works = ContractWork::get();
        $year = DB:: table('contract_works')
            ->select(DB::raw('Year(dateFailure) as dt'))
            ->groupBy('dt')
            ->orderBy('dt','asc')
            ->get();


            $thearray = (array) $year;

        return view('contratoObra.index',compact('works','year'));

mi vista donde mando la variable es la siguiente:

{!!Form::open(['route' => 'contratoObra.index', 'method' => 'GET', 'class' => 'navbar-form navbar-right pull-right'])!!}
<div class="form-group" >
  <div class="col-md-2 form-group">
    {!!Form::select('year', $year, null, ['placeholder' => 'Todo...' ])!!}
  </div>
</div>
{!!Form::submit('Filtrar',['class'=>'btn btn-primary'])!!}
{!!Form::close()!!}

solución

Utiliza el método toArray() para convertir la colección a un array: https://laravel.com/docs/master/collections#method-toarray

/**
 * Get the collection of items as a plain array.
 *
 * @return array
 */
public function toArray()
{
    return array_map(function ($value) {
        return $value instanceof Arrayable ? $value->toArray() : $value;
    }, $this->items);
}
Respondido por: Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *