2015-01-08 74 views
0

我在這個表單中有2個選擇框,第一個選擇框完成並工作。從Laravel的數據庫創建一個選擇框表單

...但是當我添加第二個選擇框,看起來像圖片中的錯誤..

這裏的代碼

這是第一個選擇框 - 它的工作原理:

{{ Form::open(array('url' =>route('units.store'), 'method' => 'post'))}} 

    <div class="form-group @if ($errors->has('brand_id')) has-error @endif"> 
    <label>Brand Manufacture</label> 
    {{Form::select('brand_id', $brand, null, ['class' => 'form-control w450']) }} 
    @if ($errors->has('brand_id')) <p class="help-block">{{ $errors->first('brand_id') }}</p> @endif 
    </div> 

這是選擇這是不對的:

<div class="form-group @if ($errors->has('model_id')) has-error @endif"> 
    <label>Model Type</label> 
    {{Form::select('model_id',$model, null, ['class' => 'form-control w450']) }} 
    @if ($errors->has('model_id')) <p class="help-block">{{ $errors->first('model_id') }}</p> @endif 
    </div> 

這是整個合作德。

{{ Form::open(array('url' =>route('units.store'), 'method' => 'post'))}} 

    <div class="form-group @if ($errors->has('brand_id')) has-error @endif"> 
    <label>Brand Manufacture</label> 
    {{Form::select('brand_id', $brand, null, ['class' => 'form-control w450']) }} 
    @if ($errors->has('brand_id')) <p class="help-block">{{ $errors->first('brand_id') }}</p> @endif 
    </div> 


    <div class="form-group @if ($errors->has('model_id')) has-error @endif"> 
    <label>Model Type</label> 
    {{Form::select('model_id',$model, null, ['class' => 'form-control w450']) }} 
    @if ($errors->has('model_id')) <p class="help-block">{{ $errors->first('model_id') }}</p> @endif 
    </div> 

    <div class="form-group @if ($errors->has('kva')) has-error @endif"> 
    <label>kva</label> 
    <input name="kva" type="text" class="form-control w450" value="{{ Input::old('kva') }}"> 
    @if ($errors->has('kva')) <p class="help-block">{{ $errors->first('kva') }}</p> @endif 
    </div> 

    <div class="form-group @if ($errors->has('type')) has-error @endif"> 
    <label>Type</label> 
    <select name="type" id="" class="form-control w450"> 
     <option value="OPEN">OPEN</option> 
     <option value="CLOSE">CLOSE</option> 
    </select> 
    @if ($errors->has('type')) <p class="help-block">{{ $errors->first('type') }}</p> @endif 
    </div> 

    <div class="form-group @if ($errors->has('sn')) has-error @endif"> 
    <label>Serial Number</label> 
    <input name="sn" type="text" class="form-control w450" value="{{ Input::old('sn') }}"> 
    @if ($errors->has('sn')) <p class="help-block">{{ $errors->first('sn') }}</p> @endif 
    </div> 

    <div class="form-group @if ($errors->has('wbs_unit')) has-error @endif"> 
    <label>WBS unit</label> 
    <input name="wbs_unit" type="text" class="form-control w450" value="{{ Input::old('wbs_unit') }}"> 
    @if ($errors->has('wbs_unit')) <p class="help-block">{{ $errors->first('wbs_unit') }}</p> @endif 
    </div> 

    <div class="form-group"> 
     <button type="submit" class="btn btn-sm btn-primary">create</button> 
    </div> 

{{ Form::close() }} 

我不能發表任何圖像:(

這樣有利於me..please

+0

這個鏈接http://file.tpops.net/?d=dXBsb2Fkcy9NSUZUQUgvZXJycnIuanBn&t=1420749231&h=2f4f95fc85a221fd7c60ea40b491ffed使用該用戶名和密碼的用戶是tpops和密碼akses鏈路tpops2015 – MTeguhFh

+0

因爲你不能張貼任何圖像,有什麼錯誤?你能正確var_dump'$模型'? – user2094178

回答

0

確保您從在選擇框的正確格式的數據庫中提取數據,它應該是一個關聯數組,鍵爲數據庫ID和值是要在下拉列表中顯示的字符串。下面是一個例子。

$brands = Brand::lists('name', 'id'); 
// Example: ['1' => 'Adidas', '2' => 'Nike', '3' => 'New Balance;]; 

{{ Form::select('brand_id', $brands) }} 

此外,您還可以簡化您的錯誤CL屁股使用三元語句,就像這樣。

<div class="form-group {{ $errors->has('brand_id') ? 'has-error' : null }}"> 
相關問題