首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >餐厅3嵌套资源?

餐厅3嵌套资源?
EN

Stack Overflow用户
提问于 2014-07-26 23:24:11
回答 1查看 304关注 0票数 0

在restler中,是否可以使用嵌套资源?例如,使用restler,我会执行普通的/api/account/123调用来获得特定的帐户。现在我想要那个帐户的客户。例如,我还想调用/api/account/123/client/456来获取特定帐户的特定客户端。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-28 03:35:38

您可以使用手动路由来定义此类路由。请参阅下面的示例

代码语言:javascript
运行
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24976430

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档