my pagination is not working correctly.when the pagination is clicked it takes time to display the result and when we click the page one after other ,the pages are continuously loaded. why this happens ...Can any one help me with 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 as $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 could not be 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 as id','restaurant.id as rest_id','restaurant.created_at as 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 as id','restaurant.id as rest_id','restaurant.created_at as user_created')->orderBy('restaurant.id','desc')
->paginate(3);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire