Support the ongoing development of Laravel.io →
Database Eloquent Forms
Last updated 7 months ago.
0

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.

Last updated 7 months ago.
0

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.

0

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

0

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.

Last updated 5 years ago.
0

Sign in to participate in this thread!

LaraJobs

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.