Learner's avatar

pagination problem

I tried to paginate but its renders class error. Where I am already added it

use Illuminate\Pagination\Paginator;
'
'
'
$rsSTDs         = $this->ResultWithSTDsRegid($input, $rc)->paginate(5);

 private function ResultWithSTDsRegid($input, $rc)
    {
        $rc =    $rc->where('Regid',   CompleteRegid($input['Regid']))
                    ->where('ExamYear', $input['ExamYear'])
                    ->where('Courseid', $input['course'])
                    ->where('Examtype', $input['Examtype'])
                    ->where('CLM','0')
                    ->get(); // I also try it here with `->paginate(5)` but not work, same issue
        return $rc;
    }


error

FatalErrorException in QueryGazettMadaris.php line 17:
Call to undefined method Illuminate\Database\Eloquent\Collection::paginate()

How to fix it.

0 likes
2 replies
jhoff's avatar

paginate() is only available on Eloquent results and Query Builders.

I'm assuming $rc is a collection.

https://laravel.com/docs/5.1/pagination#manually-creating-a-paginator

Try this instead:

 private function ResultWithSTDsRegid($input, $rc)
    {
        $rc =    $rc->where('Regid',   CompleteRegid($input['Regid']))
                    ->where('ExamYear', $input['ExamYear'])
                    ->where('Courseid', $input['course'])
                    ->where('Examtype', $input['Examtype'])
                    ->where('CLM','0')
                    ->get();
        return new \Illuminate\Pagination\Paginator( $rc, 5 );
    }

Alternately, you can return a LengthAwarePaginator, but you have to provide the length of the collection:

        return new \Illuminate\Pagination\LengthAwarePaginator( $rc, count($rc), 5 );
1 like
Learner's avatar

@jhoff thanks to reply, now its view the page, and show simple pagination, I want to show it in slide pagination page links with menually adding custom path. Because it dons't show complete url path here, it show as:

localhost/?page=2 // its not complete path, how fix it.

my complete url path is ,

http://localhost/wifaq-atropos/public/Madaris-Maktab-Nataig?page=2

next problem is that ,When i click on next page link or hit with above url, its gives route problem, I think , due to Post route

Route::group(['before' => 'csrf'], function()
{
    Route::post('Infradi-Maktab-Nataig', ['as'=>'Infradi-Maktab-Nataig', 'uses'=>'GazettController@InfradiGazett']);
    Route::post('Madaris-Maktab-Nataig', ['as'=>'Madaris-Maktab-Nataig', 'uses'=>'GazettController@MadarisGazett']);
});

how fix it.

Please or to participate in this conversation.