Posts Learn Components Snippets Categories Tags Tools About

How to get Current URL from Laravel Blade

Learn how to get the current URL from the Laravel blade template and make use of it to perform your checking logic such as active menu

Created on Oct 06, 2021


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>
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 
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.
    <li class="{{ Request::is('posts/*') ? 'active' : '' }}">

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for How to get Current URL from Laravel Blade


PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that are right for your project.

View Components

Sponsors 👑

+ Add Yours