2013-02-08 2 views
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] => '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())); 

답변

0

이 방법이 효과가 있습니까? 내가 전에 것을 시도

{{ Form::select('project', $projects) }} 
+0

번호 : 템플릿에서

$projects = Project::where('user_id', Auth::user()->id)->lists('name', 'id'); 

:

public static function get_ids() { //return DB::query('select id FROM __roles'); return DB::table('roles')->get(array('id'))->to_array(); } //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'))->to_array(); } 

+0

내가 틀렸을 수도 있지만 to_array는 설득력있는 것으로 생각합니다. – David

0

나는이 옵션을 시도했다.
관련 문제