-
-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.x] Laravel 11 support #1180
[3.x] Laravel 11 support #1180
Conversation
Tried the installation with the new Laravel 11 app skeleton and seems like everything works fine. The only different step is that you need to create an use Illuminate\Support\ServiceProvider;
return [
'providers' => ServiceProvider::defaultProviders()->merge([
App\Providers\TenancyServiceProvider::class,
])->toArray(),
]; Will keep this PR open until Laravel 11 release. To test Tenancy 3.x with Laravel 11, you can use:
If you run into any issues, let me know in this thread. |
You can add this to the ->withProviders([
// Add providers here....
]) |
What about RouteServiceProvider? Cant acces my tenant's routes, it keeps showing me my central routes.. I recreated Route ServiceProvider from Laravel 10.x and added the changes in the docs but i think the problem is here:
|
Did you apply the |
Any progress on this? Laravel 11 does not include a RouteServiceProvider by default |
@randuran See the link I posted above. You can apply the |
Think by default the route SP was used to change central routes — scope them to the central domain. The tenancy middleware is best to use directly in your tenant routes, yeah. And without a route SP, you can just scope your central routes to the central domain directly in web.php/api.php. The provider is not needed, it can just simplify your route files. |
Once we can get the tests to pass I'll merge this into 3.x and tag a release. |
It doesn't work at all, i can access to my tenant routes but i can't access to my central routes with the same URI |
Hmm, this works: // config/app.php
return [
'providers' => ServiceProvider::defaultProviders()->merge([
App\Providers\TenancyServiceProvider::class,
])->toArray(),
]; // routes/web.php
Route::domain('l11-test.test')->get('/', function () {
return view('welcome');
}); // routes/tenant.php
Route::middleware([
'web',
InitializeTenancyBySubdomain::class,
PreventAccessFromCentralDomains::class,
])->group(function () {
Route::get('/abc', function () {
return 'This is your multi-tenant application. The id of the current tenant is ' . tenant('id');
});
}); But when you change My guess would be the tenant routes get registered after the central routes, which is why it results in a 404 from the So the Tenancy SP needs to be registered in some way so that it executes after the default route SP. |
Changing TSP protected function mapRoutes()
{
$this->app->booted(function () {
if (file_exists(base_path('routes/tenant.php'))) {
Route::namespace(static::$controllerNamespace)
->group(base_path('routes/tenant.php'));
}
});
} Seems to work, though I'd like to try a few different solutions before concluding if this is the way to go. |
I did the changes on TSP and it works correctly on routes with web but when i tried to do the same on 'api' it fails routes/tenant.php
routes/api.php
UPDATE:
|
Just sharing my setup. It works in my project. Firstly, I add TSP in bootstrap/providers.php file
Secondly, In TSP, I comment out mapRoutes
And finally, in bootstrap/app.php file, following the Laravel 11 documentation, i modify withRouting function into:
|
The |
Instead of |
This isn't about registering an additional file, that's already possible in the TenancyServiceProvider. We're looking for ways to scope the central routes to central domains in a nice way. |
Using both @mfakhrys and @stancl codes...
Secondly, in
This overrides the default web routing, but this is exactly what we want to achieve. Api routes will be defined in the same way, but I think an api.php file will have to be included in the routes. I'm not using that. Finally, in TSP, we change
|
This comment was marked as off-topic.
This comment was marked as off-topic.
Keep this thread Laravel 11-related, support questions go on our Discord. |
L11 saas-boilerplate issue I'm wrestling with is the relocation of exception handling from My version of
I know it's not quite the latest version but the issues of converting it over to L11 Anyone had success with converting a saas-boilerplae based application to L11? |
This is on purpose, so that you buy the saas boilerplate! |
The boilerplate doesn't use L11. It will be updated after we have the time to go over all the project structure changes. |
how did you guys setup your central api routes? and my routing in bootstrap/app.php is like:
so when i e.g. send a request to /api/users, it uses the web.php route instead of the api.php route. |
If you use top-level |
No, I want to use it like I use web routes. Is this the correct way, because it works?
|
Here is what I got to work. Initially tested it in a fresh Laravel 11 install and then the actual project I have. Both seem to work as intended. First register two additional service providers
Next remove the
Register the
// Using the default TenancyServiceProvider, no changes needed there What seems to do the trick is not registering |
This comment was marked as spam.
This comment was marked as spam.
Don't spam ping when asking questions. The approaches outlined above work: you just have to make sure your tenant routes get registered after central routes, either in I'll update the v3 docs soon to rewrite the installation guide. |
Docs updated stancl/tenancy-docs@3f60cdb |
It's true. I believe that using 'then' is more productive. This way keep 'up/health' and others |
|
It is working for me |
This PR adds Laravel 11 support.