2014-07-26 2 views
0

restrest에서 중첩 된 리소스를 사용할 수 있습니까? 예를 들어, restler를 사용하면 정상적인 /api/account/123 호출을 통해 특정 계정을 얻을 수 있습니다. 이제 해당 계정에 속한 고객을 확보하고 싶습니다. 따라서 특정 계정에 대한 특정 클라이언트를 얻으려면 예를 들어 /api/account/123/client/456으로 전화 할 수도 있습니다.Restler 3 중첩 된 리소스?

+1

을 참조하십시오 내가 필요 정확히 것으로 보인다 가능성 https://github.com/Luracast/Restler/issues/294 – Luracast

+0

, 감사에 대해 설명 스레드입니다. – Gargoyle

답변

0

수동 라우팅을 사용하여 이러한 경로를 정의 할 수 있습니다. 다음의 예 여기

use Luracast\Restler\RestException; 

class Accounts 
{ 

    /** 
    * Get specific client for the given account 
    * 
    * @param int $id account id 
    * @param int $client_id 
    * 
    * @throws RestException 404 
    * 
    * @return Client 
    * 
    * @url GET accounts/{id}/clients/{client_id} 
    */ 
    public function getClient($id, $client_id) 
    { 
     $r = Client::where('account_id', '=', $id)->where('id', '=', $client_id)->firstOrFail(); 
     if (empty($r)) 
      throw RestException(404, 'Client is not found associated with the account'); 
     return $r; 
    } 

    /** 
    * Get all clients associated with the given account 
    * 
    * @param int $id account id 
    * 
    * @return array {@type Client} 
    * 
    * @url GET accounts/{id}/clients 
    */ 
    public function getClients($id) 
    { 
     return Client::where('account_id', '=', $id)->all(); 
    } 

} 
+0

탐색기를 개선하여 반환되는 유형과 예외가 표시되도록 할 수 있습니까? – Gargoyle

+0

RC6에서 Explorer 클래스를 사용해 보셨습니까? – Luracast

+0

RC6? github 페이지에서 RC5라고 말합니다 – Gargoyle

관련 문제