Ad

Laravel Routes, How To Group Similar In One File

- 1 answer

I'm working with laravel(5.2), and there are a lot routes in my route file.

in fresh install I noticed that it was loading auth routes something like this.

Route::auth();

nothing else was there in routes.php file related to auth routes.

in my file, I've like this one

Route::get('color/event', '[email protected]');
Route::post('color/event', '[email protected]_message);
...
...

and many others, So I want to load all in laravel way, like Route::color(); and it should load all color related routes

Thanks for you time

Ad

Answer

so, anyone if s/he is looking for same answer, I figured that out.

if you want something like Route::auth(); OR Route::color();//in my case or whatever you want to call it, you need to add custom function in your Router.php file. So solution will look like

//inside Router.php file
public function whatever(){
    $this->get('app/', '[email protected]');
    $this->post('app/new', '[email protected]');
}

and in your route.php file, you can do this.

Route::whatever();

But this is really dirty way to do that

so instead you can extend the base Router and register your router in bootstrap/app.php

$app->singleton('router', 'App\Your\Router');

so I community forces to use second approach.

for more details, have a look here.

hope someone will find this useful

Thanks.

Ad
source: stackoverflow.com
Ad