0

For some reason {{ $items->links() }} doesn't do anything.

Direct cause of this problem is that $items->getLastPage() returns 0. Same $items->getTotal().

I can change page parameter in the url and it works fine - it goes to correct page. however $items->getCurrentPage() returns 1 on each page.

Pagination works perfectly for me with other models just this one gives me problems.

Also it seems to be working fine when I create the paginator manually but I want to be able access some methods from the model so I want to use Eloquent models and not raw array.

Edited: Code:

$records = EventLog::byObject($model, $id)->paginate(10);

 static public function byObject($model, $id)
       {

           $records = DB::select([query], [params]);
           return self::getHistory($records, $model);
       }

 static public function getHistory($records, $model = '')
       {
           $ids = array();
            foreach ($records as $record) {
                array_push($ids, (int)$record->id);
            }

            $history = array();                

            if (count($ids)) {

                $history = EventLog::whereRaw('id IN (' . implode(',', array_fill(0, count($ids), '?')) . ')', $ids)
                ->with('creator')
                        ->with(array('eventfields' => function($query)
                        {
                            $query->whereRaw('field NOT LIKE \'%_id\'');
                        }))
                        ->orderBy('event_logs.created_at')
                        ->orderByRaw('(CASE WHEN eventable_type=? THEN 0 ELSE 1 END)', array($model))
                        ->orderByRaw('(CASE WHEN parent_type=? THEN 0 ELSE 1 END)', array($model));

            }
            return $history;
       }

The returned $history has the right type, is displayed correctly but the pagination is not working for some reason.

I am trying to display links using

{{ $records->links(); }}

Thanks

GrumpyHat
  • 281
  • 2
  • 15

1 Answers1

1

I've same problem here, laravel 4.1 and a query scope with fulltext search. In my case the problem was the orderByRaw (a normal orderby doesn't broke pagination links).

So my "poor" solution is to keep orderByRaw off when I need a pagination and use:

->orderBy(DB::raw('my raw orderby'));

that works

Felice Ostuni
  • 1,049
  • 1
  • 12
  • 20