Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of web routes in laravel 5.5?

I've tried the following but the return is null.

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider {
    public function boot() {

        $routeList = Route::getRoutes();

        foreach ($routeList as $value) {
            dd($value->getPath());
        }

    }

}

My route file:

<?php    
Route::namespace('admin')->group(function () {
    Route::get('admin/post', 'PostController@index')->name('posts');
    Route::get('admin/post/new', 'PostController@new')->name('post_new');
    Route::post('admin/post/save', 'SubjectController@save')->name('post_save');
});

I tried several ways, but I can not list the routes created in the web.php routes file

like image 203
Gleydson S. Tavares Avatar asked Dec 24 '22 11:12

Gleydson S. Tavares


2 Answers

This will provide every details about routes.

$routes = app('router')->getRoutes();

return  $arrays=(array) $routes;
like image 94
Sohel0415 Avatar answered Jan 14 '23 05:01

Sohel0415


If you want to use them in your controller to use the programmatically, then you can access them through the Route Class via Route::getRoutes().

    use \Route;
    dd(Route::getRoutes());

To review/analyze the list of routes however, I just use the artisan command line in the root of your application:

php artisan route:list

If you have a bash, you can even look for specific routes with grep.

php artisan route:list |grep users

Hope this helps.

like image 23
Dom DaFonte Avatar answered Jan 14 '23 07:01

Dom DaFonte