lundi 4 février 2019

Inject laravel paginator class into another class

I have:

$products = Product::where('name', 'like', '%'.$request->q.'%')
        ->paginate(15);

// do some work on $products etc...
// now because of works done on $products the pagination data is
// is not available on $products anymore

and it works just fine, now for the API response we have a separate independent class which gets the results and makes it ready for the API output, so smth like:

return ApiResponse::generate($products);

now in ApiResponse class, I want to access the pagination data! and that's the problem.

I can get current page with:

$currentPage = LengthAwarePaginator::resolveCurrentPath();

but how I can access other pagination data like total pages etc.

P.S: I don't want to create a custom paginator class, I want to access the current instantiated pagination class in another class. how can I achieve this?

Thanks



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2t6mp3S
via IFTTT

Aucun commentaire:

Enregistrer un commentaire