0

Am using same navbar for shop products and shop product. @if statement isn't working. Here is navbar:

<ul class="navbar-nav ml-auto">
      <li class="nav-item">

        @if (\Request::path('/shop'))
        <a class="nav-link js-scroll-trigger" href="#page-top">Shop</a>
        @elseif (\Request::path('/product'))
        <a class="nav-link js-scroll-trigger" href="/shop">Shop</a>             
        @endif

      </li>
      <li class="nav-item">
        <a class="nav-link js-scroll-trigger" href="#contact">Contact</a>
      </li>
    </ul>

Here is routes:

Route::view('/product', 'shop.product');
Route::get('/shop', 'ShopController@index')->name('shop.index');
1

1 Answer 1

0

You can use request()->is() function of request. as below:

@if (request()->is('shop'))
    <a class="nav-link js-scroll-trigger" href="#page-top">Shop</a>
@elseif (request()->is('product'))
    <a class="nav-link js-scroll-trigger" href="/shop">Shop</a>             
@endif
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Imran, followed the dupe question link but code still didnt work. Made a controller to bring in the request function (not sure whether was suppose to or not), then tried your request()->is() function code and it works...Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.