2015-01-08 49 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 }}"> 
相关问题