我在控制器中进行了查询并将其发送到我的刀片:
public function editContractorAssociation(DeveloperContractorAssociation $developer_contractor_association, Request $request)
{
$id = $request->id;
$developer_contractor_association = DeveloperContractorAssociation::whereHas('defect_types', function ($query) use($id) {
$query->where('developer_contractor_associations.id', $id);
})->orwhereHas('contractor', function ($query) use($id) {
$query->where('developer_contractor_associations.id', $id);
})->first();
return view('dev-admin.contractors.associations.edit', ['developer_contractor_association' => $developer_contractor_association]);
}
当我打电话给{{ $developer_contractor_association->defect_types }}我的刀片时,我得到了这个:
[
{
"id":2,
"title":"Wiring",
"details":"Fix wiring",
"created_by":"22",
"created_at":"2019-09-04 11:39:48",
"updated_at":"2019-09-04 11:39:48",
"deleted_at":null,
"is_custom":1,
"developer_id":1,
"pivot":{"dca_id":87,"defect_type_id":2}},
{"id":3,"title":"Plumbing",
"details": "Fix Pipe",
"created_by":"22",
"created_at":"2019-09-04 11:40:07",
"updated_at":"2019-09-04 11:40:07",
"deleted_at":null,
"is_custom":1,
"developer_id":1,
"pivot":{"dca_id":87,"defect_type_id":3}
}
]
现在我有一个选择字段,列出了所有存在的缺陷类型:
<select class="selectpicker {{ $errors->has('defect-type-id') ? 'is-invalid' : '' }}" name="defect-type-id[]" id="defect-type-id" multiple data-style="selectpicker-style" data-width="100%" title="Defect Types">
@foreach(App\DefectType::select('id','title')->get() as $defect_type)
<option value="{{$defect_type->id}}">{{$defect_type->title}}</option>
@endforeach
</select>
哈士奇WWW