Laravel 8 - How To Get Routes in Controller

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.

Created on: Sep 05, 2021
1,660
Laravel 8 - How To Get Routes in Controller

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>';
   }
}

And the result will be like this below:

how  to get laravel routes

I hope it helps. Thank you for reading :)

Leave a Comment