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] => '1' [id] => '2' [id] => '3')
:
는
Array ([0] => stdClass Object ([id] => 1) [1] => stdClass Object ([id] => 2) [2] => stdClass Object ([id] => 3))
나는 이런 식으로 뭔가를 좀하고 싶습니다
서식의 경우
Form::select('role', array(Role::get_ids(), Role::get_names()));
번호 : 템플릿에서
:
–내가 틀렸을 수도 있지만 to_array는 설득력있는 것으로 생각합니다. – David