在这里,我尝试使用foreach循环来循环供应商名称,但出现以下错误
<tbody style="font-size:small">
@foreach($material as $material)
<tr class="odd" role="row">
{!! Form::open(['route'=>'materialsupplier.store','class'=>'form-horizontal p-t-20']) !!}
<td>{{ $material->name }}<input type="hidden" value="{{ $material->id }}" name="mat_id"></td>
<td></td>
<td>
<div class="form-group{{ $errors->has('sup_id') ? ' has-error' : '' }}">
<div >
<select class="form-control js-cities" name="sup_id">
<option value="" selected disabled>Select Supplier</option>
@foreach ($supplier as $supplier)
<option value="{{ $supplier->id}}">{{$supplier->company_name}}</option>
@endforeach
</select>
</div>
</div>
</td>
<td>
{{ Form::submit('Save',['class'=>'far fa-trash-alt btn btn-info btn-sm btn-rounded m-b-1 m-l-5']) }}
</td>
{!! Form::close() !!}
</tr>
@endforeach
</tbody>
之后,我就这样修改我的代码
<select class="form-control js-cities" name="sup_id">
<option value="" selected disabled>Select Supplier</option>
@foreach ($supplier as $supplier)
<option value="{{ $supplier}}">{{$supplier}}</option>
@endforeach
</select>
控制器
public function index()
{
$material = Material::all();
$supplier = Supplier::all();
return view('materialMgmt.material_suppliyer.create')->withMaterial($material)->withSupplier($supplier);
}
如何避免出现此错误?
答案 0 :(得分:0)
我按如下所示更改了代码,并且可以正常工作
<select class="form-control js-cities" name="sup_id">
<option value="" selected disabled>Select Supplier</option>
@foreach ($supplier as $sup)
<option value="{{ $sup->id}}">{{$sup->company_name}}</option>
@endforeach
</select>
法特梅赫先生,谢谢您的建议。