Reputation: 1801
I have a link in my navigation top bar that I would like to remove when the user is on the registration page. I thought I would be able to use url helper for that, but it is obviously not working:
This is how I have set it up:
@if(!url('/register'))
<li>
<a class="btn btn-link" href="{{ url('/register') }}">Register</a>
</li>
@endif
Upvotes: 1
Views: 727
Reputation: 803
The simplest way (without remembering a lot of APIs) to do this is you add a variable in your method:
public function register() // if this is your page in the controller
{
return view('register')->with('no_register_link', true);
}
So that, you can check it in the template:
@if (!$no_register_link)
<li>...template...</li>
@endif
In this way, you can separate the display logic and the url itself. (In case you want to ignore it also in another page.)
Upvotes: 0
Reputation: 21681
You can use Route::getCurrentRoute()->getPath()
method for get current url like below way:
@if(Route::getCurrentRoute()->getPath() != 'register')
<li>
<a class="btn btn-link" href="{{ url('/register') }}">Register</a>
</li>
@endif
Hope this answer will help you well!
Upvotes: 0
Reputation: 163758
Use request()->is()
to detect if current URL matches string:
@if (request()->is('register*'))
Upvotes: 2