我想在Laravel中創建一個下拉列表,其中的選擇選項是來自我的數據庫的值,並且存在一些問題。在本網站的其他教程中,下拉列表查詢爲您的數據庫建立模型。我還沒有創建模型類,我不打算。在Laravel中建立下拉列表(無模型)
routes.php文件
Route::get("/user/charname", array(
'as' => 'profile-character',
'uses' => '[email protected]'
));
ProfileController.php
class ProfileController extends BaseController
{
public function dropDownList()
{
$list = DB::table('characters')->where('char_id', '128')->pluck('char_name');
return View::make('layout.profile')->with('character_options',$list);
}
}
在profile.blade.php(視圖)
<div class="selected_char">
<form action="{{ URL::route('profile-character') }}" method="post">
<li>
{{ Form::select('character_options', $list ,Input::old('character_options')) }}
</li>
</form>
</div>
通過這樣做,它說,從$列表我的觀點是未定義的。我在哪裏在視圖定義$列表,我如何落實從我的控制器,以查看$列表中,因爲這一行似乎並沒有做的工作
return View::make('layout.profile')->with('character_options',$list);
我已經完成了必要的修改在我的代碼{{表::選擇( 'character_options',$ character_options,輸入::老( 'character_options'))}}。你說的很有道理,但我不明白它爲什麼仍然不起作用。它現在說character_options是profile.blade.php中的未定義變量 –