1

I am quite new to Laravel and jQuery, so maybe this is a silly question. I am stuck and I don't know what to write in the nextSelector section of jScroll. nextSelector is supposed to contain the link to the next page, and I am using paginate() of laravel. I am trying to get infinite scrolling for the posts.

This is my home.blade.php which contains the posts and the script for jScroll:

<div class="row scroll">
    <div class="col-lg-9 col-lg-offset-1 col-md-10 col-lg-offset-1 col-sm-10 col-sm-offset-1 col-xs-10 col-xs-offset-1">
        @foreach($posts as $post)
            <div class="panel panel-default ag" id="{{$post->id}}">
                <div class="panel-heading poststyle ">{{ $post->name }}</div>
                <div class="panel-body poststyle">
                    {!! nl2br(e($post->depression)) !!}
                </div>
                <ul class="list-group">
                    <li class="list-group-item"></li>
                    <li class="list-group-item">
                        <button class="btn btn-info btn-xs option1 lc{{$post->id}}" data-idl="l{{$post->id}}" onclick="this.blur();" data-toggle="button" name="options" id="option1" autocomplete="off">
                            <span class="glyphicon glyphicon-thumbs-up"></span>
                        </button>
                        <span class = "poststyle">&nbsp;{{ $post->like }}&nbsp;</span>
                        <button class="btn btn-success btn-xs optionx dc{{$post->id}}" data-idd="d{{$post->id}}" onclick="this.blur();" data-toggle="button" name="options" id="option1" autocomplete="off">
                            <span class="glyphicon glyphicon-thumbs-down"></span>
                        </button>
                        <span class = "poststyle">&nbsp;{{ $post->dislike }}&nbsp;</span>
                    </li>
                </ul>
            </div>
            <br>
        @endforeach
            {!! $posts->render()!!}




    </div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        $('ul.pagination:visible:first').hide();
        $('.scroll').jscroll({
            loadingHtml: '<div class = "loading">&emsp;&emsp;Loading...</div>',
            debug: true,
            autoTrigger: true,
            nextSelector: '?',
            contentSelector: 'div.scroll',
            callback: function () {
                $('ul.pagination:visible:first').hide();
            }
        });
    });
</script>

This is my controller where I have used paginate():

class NavController extends Controller
{
    public function home()
    {
        $posts=Depress::orderBy('id','DESC')->paginate(5);
        return view('home')->with('posts',$posts);
    }

I have put a question mark (?) for the place where I don't know what to do (nextSelector).

Someone please help me.....

Ronit
  • 127
  • 1
  • 8
  • From your controller send `$page` to view. `if($request->input('page')) $page = $request->input('page'); else $page = 1;` And in JS: `nextSelector: '?page={{ $page }}'` See if this works. – im_tsm Jul 03 '16 at 15:48
  • what does $page denote? – Ronit Jul 03 '16 at 17:22

0 Answers0