Martney Acha
Martney Acha

Reputation: 3002

how to display both id and value in dropdown list in laravel?

This is my code in my View

 {{ Form::label('supplier_list', 'Supplier', array('class' => 'control-label')) }}
    {{ Form::select('supplier', $supplier_list, null, array('class' => 'form-control')) }}

This is my code in controller

 $supplier_list = Supplier::lists('supplier_name', 'id');

My ouput is a Dropdown of SupplierName, what would I need is a Dropdown of displaying both SupplierName and ID, How to do it in laravel 4.2 ?

Upvotes: 0

Views: 816

Answers (1)

vipul sorathiya
vipul sorathiya

Reputation: 1316

Try this:

In Controller

 $supplier_list = Supplier::lists('supplier_name', 'id')->get();

In Template

<select  name="id" class="form-control">
     <option value="">Select Supplier Name</option>
     @foreach ($supplier_list as $key => $v)
         <option value="{!! $v['id'] !!}">{!! $v['supplier_name'] !!}{!! $v['id'] !!}</option>
     @endforeach
</select>

Upvotes: 1

Related Questions