How to send two data with Laravel lists?

3

I want to send 2 values to the view with lists of laravel

admin.horarios.create

The question is this, I have this code:

public function create()
    {

        $docente   = Docente::orderBy('nombre','ASC')
                    ->where('estado',1)
                    ->lists('nombre', 'apellido' 'id');

        return    view('admin.horarios.create')
                ->with('docente', $docente);

    }

But I have an error, since it only shows me the name and not the last name.

{!! Form::select('id_docente', $docente , null, ['class' => 'form-control input-xs select2']) !!}

    
asked by Marcial Cahuaya Tarqui 02.12.2016 в 04:56
source

2 answers

5

The lists method is obsolete at this time, you should use pluck() instead.

To solve your problem you can use a accessor to generate the chain you want, add to your Teaching model:

public function getFullnameAttribute()
{
    return [$this->nombre . ' ' . $this->apellido];
}

And the query would be something like this:

$docente = Docente::orderBy('nombre', 'ASC')
                ->where('estado', 1)
                ->pluck('fullname', 'id');
    
answered by 02.12.2016 в 05:35
0

An alternative, is using query builder, and do the following:

public function create()
{

    $docente   = Docente::orderBy('nombre','ASC')
                ->selectRaw( " CONCAT('nombre', ' ', 'apellido') as nombre, id " )
                ->where('estado',1)
                ->lists('nombre', 'id');

    return    view('admin.horarios.create')
            ->with('docente', $docente);

}

and voila, that should show your name and surname.

Greetings

    
answered by 26.12.2017 в 15:05