Laravel Routes from Database Laravel Routes from Database

November 3, 2022

laravel londinium

I have grown my website to have over 8000 lines in the routes files!

These are only calling 6 controllers and simple static views, like so:

Route::get('/embassy', ['uses' =>'FeatureController@index'])->where(['feature'=>"amenity=embassy"]);

Route::get("/lidl", ['uses' =>'BrandController@index'])->where(['brand'=>"Lidl"]);

Route::get('/NW9', ['uses' =>'PlaceController@index'])->where(['lat'=>"51.58", 'long'=> "-0.25", 'feature'=> "The Hyde"]);
Route::get('/Somerset_Ilminster', ['uses' =>'PlaceController@index'])->where(['lat'=>'50.926998', 'long'=> '-2.913960', 'feature'=> 'Ilminster_(Somerset)']);

But these make up the majority of them, so now it is time to address this and move them to a database table for the feature, brand and place controllers.

I am planning to use Fallback routes as the last route in the /routes/web.php file to send them all a RouteController which will read the db and send them to the correct router.

Having a quick look at projects online on github, https://github.com/luensys/laravel-database-routes seems to import the routes from the route file into a database, and so does this one https://github.com/douma/laravel-database-routes

wonder if anyone has used these?


If you would like to contact me you can either use this form on londinium.com or via Twitter @andylondon