0
爲了使用Form :: select,你需要添加一個名字和兩個數組。在laravel中做出選擇的最佳方法?
在正常情況下,我們有一個與id和另一個與名稱。兩者都需要從查詢中加載。
因此在模型中我有這樣的事情:
public static function get_ids()
{
//return DB::query('select id FROM __roles');
return DB::table('roles')->get(array('id'));
}
//Returns an array with all the names
public static function get_names()
{
//return DB::query('select name FROM __roles');
return DB::table('roles')->get(array('name'));
}
然而,這給了我這樣的:
Array ([0] => stdClass Object ([id] => 1) [1] => stdClass Object ([id] => 2) [2] => stdClass Object ([id] => 3))
我希望得到的東西是這樣的:
Array ([0] => '1' [id] => '2' [id] => '3')
對於表格
Form::select('role', array(Role::get_ids(), Role::get_names()));
不,我試過了。 – 2013-02-08 16:40:31
我可能是錯的,但我認爲to_array只是爲了雄辯。 – David 2013-02-08 19:21:02