DEV Community

Cover image for Laravel 8 - How To Get Routes in Controller
Code And Deploy
Code And Deploy

Posted on


Laravel 8 - How To Get Routes in Controller

Originally posted @ visit and download the sample code:

In this post, I will share how to get the Laravel 8 routes inside a controller. If you need to get the routes and register them to your permissions then this is for you or maybe another checking you need in your Laravel project.

use Illuminate\Support\Facades\Route;

 * Display a listing of the resource.
 * @return \Illuminate\Http\Response
public function index()
    $routes = Route::getRoutes();
    foreach ($routes->getRoutes() as $route) {
        echo $route->getName(). '<br>';
        echo $route->getActionName(). '<br><br><br>';
Enter fullscreen mode Exit fullscreen mode

And the result will be like this below:


I hope this tutorial can help you. Kindly visit here if you want to download this code.

Happy coding :)

Top comments (0)


11 Tips That Make You a Better Typescript Programmer

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields


Read the whole post now!