Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Is it possible to check if we are on specific view with Blade?

I want to know for example if I'm currently on the page that is home.blade.php view for example

Is that possible?

0 likes
4 replies
OussamaMater's avatar

If you are using named routes you are sure that this view belongs to a certain route, so you may use the route's name instead.

Edit: this method is like a workaround, so if you have standalone (ready to be included) components that you want to know their names, it won't really work, it will work on global views that are tied to routes.

2 likes
teos_97's avatar

Not sure if this would help, but you could do this :

// App ServiceProvider @boot method
view()->composer('*', function($view){
            $view_name = str_replace('.', '-', $view->getName());
            view()->share('view_name', $view_name);
        });

This will make a variable $view_name accessible in all blade views. You could use it for some logic then. Let us know if this helps with your use case.

1 like
Snapey's avatar

I want to know for example if I'm currently on the page that is home.blade.php view for example

from where?

You want to know the route? Or the view name?

Please or to participate in this conversation.