php - Pagination not working correctly in laravel -
my pagination not working correctly.when pagination clicked takes time display result , when click page 1 after other ,the pages continuously loaded. why happens ...can 1 me this?????.............
my view.blade.php
<div class="carousel-inner" role="listbox"> <div class="item active"> <img src="{{ config::get('constants.site_url') }}public/hotel_images/{{ $rat->image }}" class="img-responsive center-object"/> </div> @if(!empty($rat->imagestore)) @foreach($rat->imagestore $image) <div class="item"> <img src="{{ config::get('constants.site_url') }}public/uploadstoreimages/{{ $image->store_image }}" class="img-responsive center-object"/> </div> @endforeach @endif </div> </div> </div> <div class="col-lg-6"> <p>{{$rat->restaurant}}</p> <p>address : {{$rat->address}} </p> <p>city : {{$rat->city}} </p> <p>zip : {{$rat->zipcode}}</p> <p>offer : {{$rat->offer}} </p> <p>price : $$ </p> <!--<p>price : {{$rat->price}} </p>--> <p>link : <a href="{{$rat->url}}">{{$rat->url}}</a> </p> <p>{{$rat->description}} </p> </div> <div class="col-lg-3"> <h3>{{$rat->phone}}</h3> <a href="#" class="special" data-toggle="modal" data-target="#mymodal_{{$rat->id}}" data_value="{{ $rat->id }}">special</a> </div> </div> </div> </div>
pagination.blade.php page
<div class="posts"> @include('front_end/stores/stores1') </div> <script> /* var url = window.location.href; var parts = url.split("?"); var result = parts[parts.length - 1]; */ $(window).on('hashchange', function() { if (window.location.hash) { var page = window.location.hash.replace('#', ''); if (page == number.nan || page <= 0) { return false; } else { getposts(page); } } }); $(document).ready(function() { $(document).on('click', '.pagination a', function (e) { getposts($(this).attr('href').split('page=')[1]); e.preventdefault(); }); }); function getposts(page) { var url = window.location.href; var parts = url.split("?"); var result = parts[parts.length - 1]; $.ajax({ url : '?page=' + page ,//'&cat_id={{ $cat_id }}', }).done(function (data) { //console.log(data); $('.posts').html(data); location.hash = page; }).fail(function () { alert('posts not loaded.'); }); } </script>
controller.php
if($cat_id != 0){ if($subcat_id == 0){ $restaurant = restaurant::leftjoin('cities','restaurant.city','=','cities.id') ->leftjoin('cuisine','restaurant.cuisine','=','cuisine.id') ->where('restaurant.category','=',$cat_id) ->select('*','restaurant.id id','restaurant.id rest_id','restaurant.created_at user_created')->orderby('restaurant.id','desc') ->paginate(3); }else{ $restaurant = restaurant::leftjoin('cities','restaurant.city','=','cities.id') ->leftjoin('cuisine','restaurant.cuisine','=','cuisine.id') ->where('restaurant.category','=',$cat_id) ->where('restaurant.subcategory','=',$subcat_id) ->select('*','restaurant.id id','restaurant.id rest_id','restaurant.created_at user_created')->orderby('restaurant.id','desc') ->paginate(3); } }
Comments
Post a Comment