Laravel select optgroup 和来自数据库的分隔值

Laravel select optgroup and separated values from database

我编写表单将值发送到数据库:

{!! 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'));
}

Laravel return 像这样在 Form::select 中编辑值:http://iv.pl/images/97320689105137896288.png

但我想要 return 这样的结果: http://iv.pl/images/48707724105931389272.png

我怎样才能只 returned name user 和 name warehouse 并且值是 Laravel 中的 id number(我用 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>

OK 我这样写:(现在 Laravel 返回的记录正确的样子:klik!

<select name="userstan_id" class="form-control">
  <optgroup label="Użytkownicy">
    @foreach($userListName as $user)
        <option value="{{ $user->id }}">{{ $user->name }}</option>
    @endforeach
  </optgroup>

  <optgroup label="Magazyny">
    @foreach($warehouseList as $warehouse)
        <option value="{{ $warehouse->id }}">{{ $warehouse->name_warehouse }}</option>
    @endforeach
  </optgroup>
</select>

其中 name="userstan_id" 是您要保存或更新记录的列的名称 ;)