0

I want to call a method multiple time and get all result as single array or anything . As example laravel Web.php file

<?php 
Route::get('/', function () {
    return view('welcome');
});
Route::get("test",'HomeController@index');

I want to get result like

$route=[
  '/'=>'',
  'test'=>"HomeController@index"
];
Donald Duck
  • 8,409
  • 22
  • 75
  • 99

1 Answers1

1

You can use this script to get all routes keyed by their url.

$routes = collect(Route::getRoutes())->mapWithKeys(function ($route) {
    return [$route->uri => $route->action['uses']];
})->toArray();

dd($routes);
naamhierzo
  • 345
  • 2
  • 8
  • Thank you for your valuable answer . I am using symfony routing component for learning purpose . But i think your answer is based on Laravel . – MD ANWAR JAHID Dec 18 '18 at 10:07