Creating dynamic routes

Submitted by bfalcao - 9 months ago

Sometimes we need to create dynamic routes based on database information. Here is an example that you can use on your projects, mostly inside your routes file, by retrieving a routes array (as example) and load them dynamically. Have fun! Bruno

// Instanciate a router class.
$router = app()->make('router');

// For instance this can come from your database.
$paths = ['path/to/route1','path/to/route2','path/to/route3'];

// Then iterate the router "get" method.
foreach($paths as $path)
    $router->get($path, 'PilotsController@index')->name('pilots.index');
  You can also use:

comments powered by Disqus