我编写表单将值发送到数据库:
{!! Form::model($product, ['method'=>'PATCH','class'=>'form-horizontal','action'=>['ProductsController@updatechangeStatus', $product->id]]) !!}
{{ Form::select('userstan_id', array(
'Użytkownicy' => array($userList),
'Magazyny' => array($warehouseList),
), null, ['class' => 'form-control'])}}
{!! Form::submit('Tak, przenieś', ['class' => 'btn btn-primary']) !!}
{!! link_to('warehouse/'. $product->id, $title = 'Anuluj', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
public function changestatus($id){
$product = Product::find($id);
$userList = User::lists('name', 'id');
$warehouseList = warehouse::lists('name_warehouse', 'id');
return view('pages.changestatus', compact('userList', 'product', 'warehouseList'));
}
LaravelForm::select
像这样返回值:http: //iv.pl/images/97320689105137896288.png
但我想返回这样的结果:http: //iv.pl/images/48707724105931389272.png
我该怎么做才能只返回名称用户和名称仓库,并且值是 Laravel 中的 id 号(我使用 foreach 进行了尝试,但在数组 foreach 中不起作用),如下所示:
<select>
<optgroup label="Użytkownicy">
<option value="1">michal</option>
<option value="2">mateusz</option>
</optgroup>
<optgroup label="Magazyny">
<option value="1">kosz</option>
<option value="2">zaginione</option>
</optgroup>
</select>