Anything? anybody?
Skip a routes group when middleware validation fails
Hello hellow !
So i am building a multitenant app, users and accounts are stored in the main database.
The app has multiple tenant types, each type uses a different database connection, and the app knows which connection to use with $account->connection
Each tenant type has different routes structures, so I've put each tenant routes in a different file under the routes folder
- routes/main/web.php
- routes/type1/web.php
- routes/type2/web.php
And mapped them all in the routes service provider. And i am using a middleware for each tenant type.
- Type1Init
- Type2Init
For my routes, i use the domain parameter as an point of entry Route::pattern('account_host', '([\da-z\.-]+)\.([a-z]{2,6})+');
And for each folder i use :
Route::middleware(['web', 'type1init'])
->namespace($this->namespace.'\Type1')
->name('type1.')
->domain('{account_host}')
->group(base_path('routes/type1/web.php'));
Route::middleware(['web', 'type2init'])
->namespace($this->namespace.'\Type2')
->name('type2.')
->domain('{account_host}')
->group(base_path('routes/type2/web.php'));
And in each middleware i verify if the account has a valid subscription, The problem is, when i access an account in the second tenant type, i get errors cause the app only access the first group of routes
My question is, can we use middlewares to skip the first group and goes to the second one? third one?
PS: I know i can use dynamic routes loading, but i actually want to cache all the routes for faster execution, so i am asking for that perticular question :)
Thanks !
Please or to participate in this conversation.