Framework: paginate ignores take() and limit()

Created on 9 Jun 2014  路  4Comments  路  Source: laravel/framework

If I try to limit my results to a given amount, it's ignored when using ->paginate($paginateLimit).

$limit = 10;
$paginateLimit = 90;
$videos = Video::with('thumbnail')
    ->whereNotNull('confirmed_at')
    ->where('confirmed_at', '<=', Carbon::now())
    ->take($limit)
    ->paginate($paginateLimit);

dd($limit, $paginateLimit, $videos->count());

Returns

int 10
int 90
int 90

Should return

int 10
int 90
int 10

If I use ->get() instead of ->paginate(...) it works. Shouldn't ->paginate(...) work with ->limit($limit) and ->take($limit)?

I want to use the function of ->paginate(...) without needing to access the entire table.


I'm on "laravel/framework": "4.2.*", with "minimum-stability": "stable".

All 4 comments

But... paginate needs to set its own LIMIT, that's the point of pagination, if you define that yourself, why would you use paginate?

Say if you only want only the first three pages. Then you don't want to access the entire table, only the first three pages.

In my case I list currently watched videos, if that list is empty I want to randomize a couple of videos but still use the paginate function so I don't need to check if the variable is an instance of Paginate.

I tried with

$videos = Video::with('thumbnail')
    ->whereNotNull('confirmed_at')
    ->where('confirmed_at', '<=', Carbon::now())
    ->orderBy(DB::raw('RAND()'))
    ->take($limit)
    ->get();
    //->paginate($this->paginateLimit);

$videos = Paginator::make($videos->toArray(), $videos->count(), $limit);

but that doesn't work as I can't access Eloquent methods if it's an array.

I got it to work by using $videos->all() instead of ->toArray().

same problem, moreover i get all the result at a place but pagination.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

klimentLambevski picture klimentLambevski  路  3Comments

ghost picture ghost  路  3Comments

JamborJan picture JamborJan  路  3Comments

YannPl picture YannPl  路  3Comments

CupOfTea696 picture CupOfTea696  路  3Comments