0

I write form to send values to 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 returned values in Form::select like this: http://iv.pl/images/97320689105137896288.png

but I want to return a result like this: http://iv.pl/images/48707724105931389272.png

How can I do to be returned only name user and name warehouse and value was id number in Laravel (I tring with foreach, but in array foreach not working), like this:

<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>
major697
  • 139
  • 1
  • 2
  • 15

1 Answers1

0

OK I write this: (now Laravel returned records correct look: 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>

Where name="userstan_id" is name of column where you want save or update record ;)

major697
  • 139
  • 1
  • 2
  • 15