简体   繁体   English

laravel:如何在单击第二个分页的下一页时删除第一个分页

[英]laravel: how to remove first pagination when click next page of 2nd pagination

i have index page with two pagination passing to.我有两个分页传递到的索引页。 first i gave to slide to show featured items and then there is other items after that slider coming through 2nd pagination.首先我让幻灯片显示特色项目,然后在该滑块通过第二个分页之后还有其他项目。 but when i click next page.但是当我点击下一页时。 the first pagination items doesn't show but the header of that div remains.第一个分页项不显示,但该 div 的标题仍然存在。 my question is what i can do to remove that whole div of slider of featured items on any other page than index page and page after ?page=1 at url.我的问题是我可以做些什么来删除任何其他页面上的特色项目滑块的整个 div,而不是索引页和 ?page=1 at url 之后的页面。 i tried to put if condition but when there is not get value at url it give me error.我试图放置 if 条件,但是当 url 没有获取值时,它会给我错误。 is there any solution that can hide whole slider div on any other page than 1 and simple index.是否有任何解决方案可以在除 1 和简单索引之外的任何其他页面上隐藏整个滑块 div。

    class IndexController extends Controller
    {
        public function Index(){
            //Get all Products 
            $allProducts = DB::table('categories')
                ->join('products','products.category_id','=', 'categories.id')
                ->where('categories.status','=','1')->where('products.status','=','1')->paginate(9);


            // Get featured products
            $featuredProducts = DB::table('categories')
                ->join('products','products.category_id','=', 'categories.id')
                ->where('categories.status','=','1')->where('products.status','=','1')->where('feature_item',1)->paginate(25);


            //Get all Categories and sub Categories
            $categories = Category::with('categories')->where(['parent_id'=>0])->get();

            $banners = Banner::where('status','1')->get();

            return view('index')->with(compact('featuredProducts','allProducts','categories','banners'));

        }
    }

   <section>
    <div class="container">
        <div class="row">
            <div class="col-sm-3">
                @include('layouts.frontLayout.front_sidebar')
            </div>
              <div class="col-sm-9 padding-right">
                 <div class="features_items">
                    <h2 class="title text-center">Featured Items</h2>
                    <div id="recommended-item-carousel" class="carousel slide" data-ride="carousel">
                        <div class="carousel-inner">
                            <?php $count=1; ?> 
                            @foreach($featuredProducts->chunk(3) as $chunk)
                                <div <?php if($count==1){ ?> class="item active" <?php }else{ ?> class="item" <?php } ?>>
                                    @foreach($chunk as $item)   
                                        <div class="col-sm-4">
                                            <div class="product-image-wrapper">
                                                <div class="single-products">
                                                    <div class="productinfo text-center">
                                                        <img style="width:200px;" src="{{ asset('images/backend_images/products/small/'.$item->image) }}" alt="" />
                                                        <h2>$ {{ $item->price }} </h2>
                                                        <p> {{ $item->product_name }}</p>
                                                        <a href="{{ url('/product/'.$item->id) }}">
                                                            <button type="button" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</button>
                                                        </a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    @endforeach
                                </div>
                            <?php $count++; ?>
                            @endforeach
                        </div>
                         <a class="left recommended-item-control" href="#recommended-item-carousel" data-slide="prev">
                            <i class="fa fa-angle-left"></i>
                          </a>
                          <a class="right recommended-item-control" href="#recommended-item-carousel" data-slide="next">
                            <i class="fa fa-angle-right"></i>
                          </a>          
                    </div>
                 </div>
              </div>
        </div>
    </div>
    <div class="container">
        <div class="row">
            <div class="col-sm-3">

            </div>
            <div class="col-sm-9 padding-right">
                <div class="features_items"><!--features_items-->
                    <h2 class="title text-center">All Items</h2>
                    @foreach($allProducts as $product)
                    <div class="col-sm-4">
                        <a class="product-image-wrapper" href="{{ url('product/'.$product->id) }}">
                            <div class="single-products">
                                    <div class="productinfo text-center">
                                        <img src="{{ asset('images/backend_images/products/small/'.$product->image) }}" alt="" />
                                        <h2>C$ {{ $product->price }}</h2>
                                        <p>{{ $product->product_name }}</p>
                                        <a href="{{ url('product/'.$product->id) }}" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
                                    </div>
                            </div>
                        </a>
                    </div>
                    @endforeach
                </div><!--features_items--> 
                <div align="center">{{ $allProducts->links() }}</div>
            </div>
        </div>
    </div>
</section>

You can use request()->getQueryString() to check against the query parameters.您可以使用request()->getQueryString()来检查查询参数。

@if (!str_contains(request()->getQueryString(), 'page')) || (str_contains(request()->getQueryString(), 'page=1'))
  // show pagination only if page is 1 or there is no page param
@endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM