Php 使用Laravel REST api传递2个参数[Laravel 5]

Php 使用Laravel REST api传递2个参数[Laravel 5],php,api,laravel-5,Php,Api,Laravel 5,我的路线中需要有2个参数: /api/comments/2/?page=2 第一个用于整页,第二个用于该页上的项目(页码) I用户REST api: Route::resource('api/comments', 'CommentController'); 这是我的控制器,对于show method,我只能通过一个参数,但我需要2个: public function show($id, Comment $comm) { } 这是我的模型: public function apiGetCo

我的路线中需要有2个参数:

/api/comments/2/?page=2
第一个用于整页,第二个用于该页上的项目(页码)

I用户REST api:

Route::resource('api/comments', 'CommentController');
这是我的控制器,对于show method,我只能通过一个参数,但我需要2个:

public function show($id,  Comment $comm)
{

}

这是我的模型:

public function apiGetComments($id){
    $this->id = $id;
    if(ctype_digit($id)){
    $data = $this->recusative(0);
    $page = 1; // Get the current page or default to 1, this is what you miss!
    $perPage = 1;
    $offset = ($page * $perPage) - $perPage;
    return new LengthAwarePaginator(array_slice($data, $offset, $perPage, true), count($data), $perPage, $page, ['path' => Request::url(), 'query' => Request::query()]);
    }
}
当我这样做的时候:

localhost/api/comments/1/?page=1
然后换一页

localhost/api/comments/1/?page=2

没有什么变化。。。我只有第一页的第一个链接。。。有人能帮我解决这个问题吗?

您正在将
页面
变量设置为
1
,而不是可能存在的请求变量-然后将其传递给
LengthAwarePaginator

尝试:

localhost/api/comments/1/?page=2
$page = Request::input('page') ?: 1;