php - Restler 3 nested resources? -
In the restorer, is it possible to use nested resources? For example, with the rest, I would call normal / api / account / 123
to get that particular account, now I want to get customers related to that account. Therefore, I want to call / api / account / 123 / client / 456
for example to get specific clients for specific code.
You can use manual routing to define such routes. See the following example
Use Lucast / Resteller \ RestException; Class accounts {** ** Get specific customers for the given account * * @ Ultimate Int $ id account id * @ param int $ client_id * * @ thru rest exception 404 * * @ reton client * * @ resin GET account / {Id} ('id', '=') (Where '(' account_id ',' = ', $ id) - & gt; ($ id = $ client_id) {$ id = $ client_id} / / client / { Client_id} * / public function getClient, $ Client_id) - & gt; First orphan (); If (empty ($ r) throwing RestException (404, 'Client account is not associated with'); Return $ R; } / ** * Get all the customers related to the given account * * @ Ultimate IntraTr $ ID Account ID * * * Returns array {@ Type client} * * @url GET account / {ID} / Client * / Public function GetClients ($ Id) {return Client :: where ('account_id', '=', $ id) - & gt; all (); }}
Comments
Post a Comment