4

So basically, I want to create my own Route::custom function.

This is because I've been using the same groups and middleware for several routes throughout the site (I'm also using modules with subdomains, so we're talking about saving 5-6 lines of code per route)

All I want is for Route::custom to just call two or three other Route functions. For example:

Route::Module('forum') to be replaced with

Route::group(['middleware' => ['web','auth'], 'domain' => 'forum.' . env('SITE_DOMAIN', 'example.com')], function () {
    Route::group(['middleware' => 'permission:access.forum'], function () {
        Route::get('/', function () {
            return view('forum::forum.index');
        })->name("forum.index");
    });
});
theomessin
  • 754
  • 4
  • 13

2 Answers2

2

You can extends laravel default facade then add static method as you want.
Notice: You must replace route facade config in config/app.php to your custom facade class.
Example here

0

I do not understand properly question 1. But for question 2, try this:

Go to app/Providers/RouteServiceProvider.php. Look for the function mapWebRoutes(). The line

require base_path('routes/web.php');

Duplicate it and change so you now have :

require base_path('routes/web.php');
require base_path('app/User/route.user.php');
require base_path('app/Whatever/route.whatever.php');

I guess this will resolve for your problem