How to Get Current Route Name in Laravel
In this comprehensive tutorial, you'll master the art of retrieving the current route name using Laravel versions 6 through 10. Unveil multiple strategies to effortlessly fetch the route name within controllers, middleware, or blade files. Let's embark on this journey:
Get route name in Controller or Middleware
1. You can get the route name using the route facade in the controller or middleware
use Illuminate\Support\Facades\Route;
public function index(){
$routeName = Route::currentRouteName();
dd($routeName);
}2. Using request facade to get the current route name
public function index(){
$routeName = \Request::route()->getName();
dd($routeName);
}Get the route name in Blade View
Similarly, you can also use in blade file to get the current route
{{ Route::currentRouteName() }}
Thanks for your time, hope it will help you to getting the route name in the controller, middleware or in the view where you want.
Connect with KoderSolution 🚀
Master modern software engineering, scalable architectures, and advanced backend systems.
Read more architectural deep-dives, systems tutorials, and engineering guides on kodersolution.com.
Subscribe to @kodersolution for concise, animated system design breakdowns and technical shorts.
Follow our official page for daily development tips, architecture discussions, and community updates.
Callum Davies
PHP & Laravel practitioner since v5.4. Big believer in thin controllers, explicit return types, and boring modular architecture that doesn't page you on weekends.