1

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. 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. i tried to put if condition but when there is not get value at url it give me error. is there any solution that can hide whole slider div on any other page than 1 and simple index.

    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>
senty
  • 12,385
  • 28
  • 130
  • 260
osama
  • 13
  • 7
  • 1
    Can you show some code? – senty Dec 28 '19 at 17:20
  • which? controller and index both? – osama Dec 28 '19 at 17:24
  • i have updated the code. dont mind the mixed up the section tag is from index.blade file. let me know what else i need to provide – osama Dec 28 '19 at 17:36
  • So is the problem that your paginations are getting mixed? If so, check out this approach https://stackoverflow.com/a/24089478/4705339 – senty Dec 28 '19 at 17:40
  • i have seen that one but my issue is i dont want featured section to be shown at all at page 2 or onward. – osama Dec 28 '19 at 17:44
  • How about something like: `@if (!str_contains(request()->getQueryString(), 'page')) // show pagination @endif` – senty Dec 28 '19 at 17:46
  • it works but when i click page 1 which is index page just with ?page=1 at url it should show too – osama Dec 28 '19 at 18:00
  • something like this maybe? `@if (!str_contains(request()->getQueryString(), 'page')) || (str_contains(request()->getQueryString(), 'page=1'))` – senty Dec 28 '19 at 18:07
  • omg yess!!! thank you. i am new to laravel so these things were going above me the one you suggested. i will read into them. much appreciated man it was fast response. – osama Dec 28 '19 at 18:14
  • Great :) I added an answer too :) – senty Dec 28 '19 at 18:18

1 Answers1

0

You can use request()->getQueryString() to check against the query parameters.

@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
senty
  • 12,385
  • 28
  • 130
  • 260