I need to have 2 params inside my route:
/api/comments/2/?page=2
First for whole page second for items on that page(pagintaion)
I user REST api:
Route::resource('api/comments', 'CommentController');
and here is my controller, for show method I can just past one param, but I need 2:
public function show($id, Comment $comm)
{
return $comm->apiGetComments($id);
}
And here is my model:
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()]);
}
}
I can get 1 post on currnet page but my pagination don't work bacause just one param is sent anyone can help me solve this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire