我想从下拉选择框中获取所选值或项目的 id,因为我想将其保存在数据库中。所以,我尝试将它作为一个值传递,以便在页面上使用隐藏字段来获取它,但它确实有效。我该怎么做呢?
这是表单页面:
<p>{!! Form::select('companyname', array('' => 'Select a Company') + $listCompanies) !!} </p>
@foreach($istCompaniesId as $company)
@if(companyname->text === $listCompaniesId->value)
{!! Form::hidden('company_id', $listCompaniesId->value) !!}
@endif
@endforeach
这是控制器:
$listCompanies = Company::where('user_id', '=', Auth::user()->id)->orderBy('companyname', 'desc')->lists('companyname', 'companyname')->toArray();
$listCompaniesId = Company::where('user_id', '=', Auth::user()->id)->orderBy('companyname', 'desc')->lists('companyname', 'id')->toArray();
return view('product.create')
->with('listCompanies', $listCompanies)
->with('listCompaniesId', $listCompaniesId);