How to pass id when selecting value through the list box. when i click on the list box name should appear but when i click save it on database it id should be insert the id of that name in the list box.
We cannot help by guessing.. :)
If you're talking about select boxes, the value you insert into the 'value' attribute is sent through the form and you can access it by referencing the 'name' attribute of the select box.
If that's what you're asking.
<select name="choices">
<option value="1">First Choice</option>
</select>
as mentioned, the options VALUE is sent with the form.
$request->input('choices') == 1
View
@foreach ($suppliers as $key=>$value)
<input list="supplier" name="supplier">
<datalist id="supplier">
<option value="{{$value}}">
</datalist>
@endforeach
Controller
public function create()
{
$suppliers= Supplier::pluck('company_name', 'id');
return view('product.index',compact('suppliers'));
}
This should do it:
<input list="supplier" name="supplier">
@foreach ($suppliers as $key=>$value)
<datalist id="supplier">
<option value="{{$key}}">{{$value}}</option>
</datalist>
@endforeach
Please sign in or create an account to participate in this conversation.