码迷,mamicode.com
首页 > 其他好文 > 详细

laravel paginate动态分页

时间:2015-10-05 18:08:07      阅读:401      评论:0      收藏:0      [点我收藏+]

标签:

1.router

Route::get(‘product‘, function(){
    $products = App\Product::paginate(10);
    return view(‘product.index‘, compact(‘products‘));
});

Route::get(‘ajax/product‘, function(){
    $products = App\Product::paginate(10);
    return view(‘product.indexAjax‘, compact(‘products‘));
});

2.indexAjax.blade.php

<div class="row">
        <div class="col-md-6 col-md-offset-3">
            <h2>Products list</h2>
            <ul>
                @foreach($products as $product)
                    <li><h3>{{ $product->name }}</h3><span class=‘pull-right‘>{{ $product->id }}</span></li>
                @endforeach
            </ul>
            {!! $products->render() !!}
        </div>
</div>

3.js

    <script type="text/javascript">
    $(document).on(‘click‘, ‘.pagination a‘, function(e){
        e.preventDefault();

        page = $(this).attr(‘href‘).split(‘page=‘)[1];

        getProducts(page);
    });

    function getProducts(page){
        $.ajax({
            url : ‘ajax/product?page=‘ + page,
        }).done(function(date){
            $(‘.container‘).html(date);
            location.hash = page;
        });
    }
    </script>

 

laravel paginate动态分页

标签:

原文地址:http://www.cnblogs.com/fenle/p/4855969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!