Laravel 10|9|8 Get Current Route Name in Blade, Controller Tutorial

To get current route name, Path in laravel; Through this tutorial, we will learn how to get current route name, path on blade view and controller file in laravel 10|9|8 apps.

How to Get Current Route Name, Path in Laravel 10|9|8

Here are two ways to get current route name, path on blade view, and controller file in laravel 10|9|8 apps; is as follows:

  • To Get Current Route Name in Controller
  • To Get Current Route Name in Blade View

To Get Current Route Name in Controller

If we want to get the route name, and route path on controller file in laravel apps; So, we can use the following method to get route name and route path on controller file; as follows:

First, include the Route facade to your controller:

use Illuminate\Support\Facades\Route;

then use the following code into controller file:

    public function yourMethodHere(){
        $routeName = Route::currentRouteName();
	dd($routeName);

        $routeName = Route::getCurrentRoute()->getPath()
        print($routeName)
    }  

We can also use the Request facade to get the route name. For example, we can use the following code:

$routeName = Route::getCurrentRoute()->getPath()
print($routeName)

To Get Current Route Name in Blade View

If we want to get the route name, route path on blade view file in laravel apps; So, we can use the following method to get route name and route path on blade view file; as follows:

use the Route facade directly in your Blade view:

{{ Route::currentRouteName() }}

Conclusion

That’s it; you have learned how to get current route name, path on blade view and controller file in laravel 10|9|8 apps.

Recommended Laravel Tutorials

Recommended:-Laravel Try Catch

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *