You should be able add an alias via a SELECT clause to the columns you want to join up, and then reference that in the LISTS() call.
$list = MyModel::select(
DB::raw("(first_name +' '+ last_name) AS full_name, id")
)->lists('full_name', 'id');
I can't remember the order of the key/value for LISTS(), but that should do it.
Hey!
Thanks for the pointer. I needed to make some changes and this works fine for me:
DB::raw("CONCAT(first_name,' ', last_name) AS full_name, id")
But thanks for pointing me in the right direction.
You should always create your queries on mysql and make sure thy work it should be something like this
CONCAT(first_name, ' ', last_name) AS full_name, id ( note that there's a space between the 2 single quotes), then make it work the laravel way
This does not works (L5.2) in a {!! Form::select !!}}.
While in tinker has the right answare, i obtain an empty list (only "option value=" is set ti ID) in the select control tag:
{!! Form::select('driver_id', App\Driver::select(DB::raw("CONCAT(first_name,' ', last_name) AS full_name, id"))->pluck('full_name','id'), null, ['class' => 'form-control']) !!}
Why ? Thank you.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community