1

We are using Laravel 6 for a small website and dont use a database for it. I could not find any hints on where to define a custom menu. In my understanding it would be a good idea to create a component or view that just lists all the available routes and renders them as an unordered list, for instance. I then would include that view in my header blade template.

Using something like {{ Route::getRoutes() }} inside a blade template didnt work.

Alex
  • 9,911
  • 5
  • 33
  • 52
  • 1
    "*Using something like `{{ Route::getRoutes() }}` inside a blade template didn't work*" - No, I wouldn't expect that to work at all. `Route::getRoutes()` returns a `RouteCollection`; you'd need to loop over the routes in that and output a `
  • ` element (or similar) for each.
  • – Tim Lewis Oct 25 '19 at 14:36
  • @TimLewis I guessed so, but I have a hard time finding documentation on this. Can you provide some further links to dig into? Thanks – Alex Oct 25 '19 at 14:37
  • 1
    Takes a bit of digging into the components API, but that's available here: https://laravel.com/api/5.8/Illuminate/Routing/Router.html#method_getRoutes, https://laravel.com/api/5.8/Illuminate/Routing/RouteCollection.html#method_getRoutes and https://laravel.com/api/5.8/Illuminate/Routing/Route.html#method_uri. The actual call would be `@foreach(Route::getRoutes()->getRoutes() AS $route)
  • {{ $route->uri }}
  • @endforeach` (or similar). Have to double the `->getRoutes()` call in Laravel 5.2+ – Tim Lewis Oct 25 '19 at 14:41
  • @TimLewis thanks! it works. do you have a hint on how to load only the custom routes? it also loads internal/ ignition routes. – Alex Oct 25 '19 at 14:45
  • Could do some string matching, or if your custom routes are named, match them against https://laravel.com/api/5.8/Illuminate/Routing/Route.html#method_named, etc. Do you have too many routes that you can't hard code the URLs? Writing a bunch of `
  • Example
  • ` isn't too hard generally. (replace with `route('name')` if using named routes) – Tim Lewis Oct 25 '19 at 14:51