我有一個數據庫表,存儲國家的名單,現在我試圖以下拉形式獲得國家的名單,但沒有工作,也許是缺少something.this是我的控制器代碼Laravel如何從數據庫填充選擇框
` public function details($id){
//fetch post data
//$post = Post::find($id);
$country_options = Country::pluck('country', 'id');
$country_options = DB::table('regions')->orderBy('country', 'asc')->pluck('country','id');
//pass posts data to view and load list view
return view('dashboard')->with('country_options',$country_options);
}`
和呼應下拉我的形式看起來像這樣''
@foreach($countries as $country)'+
'<option value="{{ $country->id }}"> {{ $country->country }}</option>'+
'@endforeach'+`
和我的路線是這樣的
Route::get('/Business', '[email protected]')->name('Business');
0123碼
但我不斷收到此錯誤信息
Undefined variable: countries (View: C:\xampp\htdocs
已經取得的研究,但不能罰款的解決方案。 任何幫助將不勝感激與正確的文件/ explain.thanks
我注意到的第一件事是你使用'$ countries'在視圖中,但在控制器中,您正在傳遞'country_options'來查看。 – Bostjan