Laravel - check if routes on blade
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Title: Checking Routes on Blade Views in Laravel
Introduction: In Laravel, you can check whether a user is on a specific route by using the `Route::current()` method available within your views. This blog post will provide a comprehensive answer to checking routes on blade views and offer best practices for doing so.
Body: Laravel's Route class offers various methods that enable developers to access information about the current route a user is on. You can use `Route::current()->uri()` along with conditional statements, like an if-else block, to display specific content in your views based on the user's location.
Here are some examples of Laravel routes and related view logic:
1. Checking a single route: In this case, you want to display additional content only when the user is not on the home page. You can use the following code snippet in your Blade template:
@if (Route::current()->uri() != '/') <div>add some content some contnt </div> @endif
In this example, you're checking if the current route's URI is not equal to `'/'`, which means it isn't the home page. You can replace the URI with another valid route name or regular expression pattern that matches the desired route. Using the above code will display the given content only when the user is on a different route.
2. Checking multiple routes: Let's say you have two distinct conditions - one for checking if the current route is not the home page, and another for ensuring it isn't the 'login' route. You can combine these conditions using `||` (or) operator in your Blade template as follows:
@if (Route::current()->uri() != '/' || Route::current()->uri() != 'login')<div>add some content some contnt </div> @endif
In this example, the code checks whether the user isn't on the home page or the login page. It ensures that the additional content is only displayed when these conditions are met.
3. Alternative methods: Apart from `Route::current()->uri()`, you can also use other route-related methods like `Request::path()` to check the current URI. Here's an example of using `Request::path()` in your Blade template:
@if (!Request::path() == '/') <div>add some content some contnt </div> @endif
In this case, the double exclamation mark (!!) is used to invert the result of the condition `!Request::path() == '/'`. This ensures that when the current route is not the home page, the additional content will be displayed. However, note that using this method may be less clear regarding its intent compared to the other examples.
Conclusion: Checking the routes on your Laravel views can be achieved by utilizing built-in methods like `Route::current()->uri()` and `Request::path()`. Keep in mind that you need to ensure proper usage and appropriate conditions for your specific requirements. By incorporating the correct code examples into your Blade templates, you can effectively add or remove content based on the user's current location within your application.