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

2
  • We need your code to help you. Please post the code where you setup pagination. Commented Jan 18, 2014 at 20:36
  • @chris342423 I have just added my code. Commented Jan 21, 2014 at 21:20

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I actually figured that out myself and forgot to add here, thanks very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.