1
我有一個編輯頁面,其中傳遞產品的數據,在這個頁面上,我有一個選擇框用於類別更改,其中我需要插入在我的數據庫中註冊的所有類別,但只顯示與該類別相關的類別頁面的產品。在Laravel 5.4中如何使用數據庫填充選擇框?
編輯視圖的選擇框
<select class="selectpicker" data-live-search="true">
@foreach($produtos->categoria as $categoria)
<option data-tokens="{{$categoria->erp_name}}" value="{{$categoria->erp_categoryid}}">{{$categoria->erp_name}}</option>
@endforeach
</select>
ProdutosController
public function edit($id)
{
$produtos = Produtos::find($id);
return view('functions.edit')->with('produtos', $produtos);
}
路線
Route::get('/product/update/{id}', '[email protected]')->name("product::updateGet");
Route::post('/product/update/{id}', '[email protected]')->name("product::updatePost");
任何sugge stions?
抓住所有的類別,將其分配給另一個變量,並通過在爲好。然後用它來代替。 – aynber
使用'$ categories = Categoria :: all()'獲取並且通過' - >與('categories',$ categories)'然後在視圖中使用它。 – siddiq