HamsiKafalu's avatar

Pagination not rendering next results

i have a strange problem here which i never had any issues until now

when you paginate results and when you click the next page it should return the next results but when i click the next page it just reloads the same page, meaning it displays the same results

this is my route

Route::group(['prefix' => 'videos'], function () {
    Route::get('/', 'VideosController@allVideos');
    Route::get('all', 'VideosController@allVideos')->name('videos.all');
});

and this is my VideosController

public function allVideos()
{
    $video = Video::paginate(12);
    return view('frontend.videos.index')
        ->with('video', $video)
        ->with('title', 'All Videos');
}

and this is my view

    <div class="col-md-9 col-sm-8">
        <div id="result-video-filter-page">
            <div class="row">
                @foreach($video as $result)
                <div class="col-sm-6 col-md-4 col-lg-4">
                    <div class="well well-sm well-shadow">
                        <a href="{{ url('watch')}}/{{$result->string_id.'/'.$result->post_name}}">
                            <span class="thumb-overlay">
                                <img src="{{$result->getImageUrl($result->poster)}}" alt="{{$result->title_name}}" class="img-responsive ">
                                <div class="hd-text-icon">HD</div>
                                <span class="duration">{{sec2hms($result->duration)}}</span>
                            </span>
                            <span class="video-detail">
                                <span class="video-title title-truncate m-t-5">{{$result->title_name}}</span>
                                <span class="video-views pull-left">{{ $result->created_at->diffForHumans() }}</span>
                            </span>
                        </a>
                        <div class="clearfix"></div>
                    </div>
                </div>
                @endforeach
            </div>
            <div  class="page_navigation">
                {{ $video->links() }}
            </div>
        </div>
    </div>

so why is this not working ? im using laravel since version 4 and i had never an issue using pagination

btw im using laravel 5.4.18 and did not test this on previous version

0 likes
7 replies
agCepeda's avatar

You should set the number of page you want to load in the code of controller.

public function allVideos(Request $request)
{
    $page = $request->get('page', 1);
    $video = Video::paginate(12, $page);
    return view('frontend.videos.index')
        ->with('video', $video)
        ->with('title', 'All Videos');
}
HamsiKafalu's avatar

@agCepeda thats not how i did in my other project.. my code should actually work because thats how the pagination works

https://laravel.com/docs/master/pagination

btw your suggestion gives my an error

Type error: Argument 1 passed to Illuminate\Database\Grammar::columnize() must be of the type array, integer given, called in 
3 likes
agCepeda's avatar

It doesn't work because you send a String, you should change one line of code.

public function allVideos(Request $request)
{
    $page = $request->get('page', 1);
    $video = Video::paginate(12, intval($page));
    return view('frontend.videos.index')
        ->with('video', $video)
        ->with('title', 'All Videos');
}
HamsiKafalu's avatar

@agCepeda i think i know why this is not working i think that i have misconfigured my nginx but im not sure

HamsiKafalu's avatar

@agCepeda yeppp i had misconfigured my ngnix it now fixed by

changing

try_files $uri $uri/ /index.php$args;

to

try_files $uri $uri/ /index.php?$query_string;
4 likes
ajlalhaider13's avatar

Thanks for posting the solution. I had tried everything in my code and wasn't sure why it wasn't working.

1 like

Please or to participate in this conversation.