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".
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.