Search code examples
laravellaravelcollectivelaravel-6

How to return a value from database to LaravelCollective Dropdown?


My LaravelCollective dropdown doesn't return value as expected right now the dropdown looks like this enter image description here

I want that dropdown just return value from nama column

This is my Controller

public function create()
    {
        $supplierList = Supplier::select('idSupplier', 'nama')->get();
        return view('transactionsIN.create', compact('supplierList'));
    }

and this is my LaravelCollective on blade.php page

{!! Form::select('id_Supplier',$supplierList, null, ['class'=>'form-control', 'placeholder' => 'Pilih salah satu supplier...']) !!}

Solution

  • You need to loop to the array of $supplierList then call

    {!! Form::select('id_Supplier',$supplierList->pluck('nama'), null, ['class'=>'form-control', 'placeholder' => 'Pilih salah satu supplier...']) !!}