2014-10-24 6 views
0

Eloquent를 사용하는 사용자 배열을 가진 단일 객체가되도록 내 응답을 얻을 수있는 방법이 있습니까? 예를 들어단일 json 객체로 배열의 Laravel 결과 표시

:

{ 
    "results" : [ 
       { "email" : "[email protected]" }, 
       { "email" : "[email protected]" } 
       ] 
} 

현재는이 같은 출력 :

$users = User::whereIn('number', $numbers)->select('email')->get(); 
return $users; 

것이 잘 될 것이다 : 내 코드로부터 사용자를 표시하고있어 어떻게

[ 
    { 
     "email": "[email protected]", 
    }, 
    { 
     "email": "[email protected]", 
    } 
] 

입니다 하지만 JSONObjectRequest을 사용하는 Android 용 Volley를 사용하고 있지만 JSON becau를 구문 분석하려고 할 때 실패합니다. 그것은 배열을 구문 분석 할 수 없습니다.

답변

1

이처럼 시도 할 수 있습니다 :

$users = User::whereIn('number', $numbers)->select('email')->get(); 
return Response::json(array('results' => $users));