2015-09-23 97 views
2

我需要我的路線內2個PARAMS:通2個PARAMS與Laravel REST API [Laravel 5]

/api/comments/2/?page=2 

首先對整個頁面第二的項目在該頁面(pagintaion)

我用戶REST API:

Route::resource('api/comments', 'CommentController'); 

,這裏是我的控制器,用於展示方法我可以剛剛過去的一個PARAM,但我需要2:

public function show($id, Comment $comm) 

{

return $comm->apiGetComments($id); 

}

這裏是我的模型:

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頁的第一個鏈接......任何人都可以幫我解決這個問題?

回答

1

您正在將page變量設置爲1而不是可能存在的請求變量 - 然後您將該變量傳遞給LengthAwarePaginator

嘗試:

$page = Request::input('page') ?: 1;