To get the current URL in the Laravel Blade template you can make use of the "url()" helper function which is available globally. This helper can right away be called from the blade template and you can perform conditions based on the value it's returning.
Getting Current URL in Laravel
To get the current URL you can call the "url()" function and then chaining it with the "current()" function which will return the current page URL.@if (url()->current() === 'your-the-url-value')
<h1>Do show something here</h1>
@endif
Do note that when using this method you can get the URL path value and from the result, you can determine whether to show or hide values to the user.
@if (Request::is('users'))
User name
@endif
Some of the other ways to write the logic above are to write it like below and you will be able to define the active state when you are on the right page.
<ul>
<li class="{{ Request::is('posts/*') ? 'active' : '' }}">
Posts
</li>
</ul>
Leave a reply