0

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

{!! 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>
4

1 回答 1

0

好的,我这样写:(现在 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"您要保存或更新记录的列的名称在哪里;)

于 2016-07-23T18:27:23.070 回答