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
This will provide every details about routes
.
$routes = app('router')->getRoutes();
return $arrays=(array) $routes;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With