I am using the Stancl/Tenancy package in laravel for multi-tenancy system.
I’m able to login from the central app but not from the tenant app in my localhost. I have created a virtual central domain in localhost named sms.com and a subdomain named tenant1.sms.com
When I open the central domain the login page appears and I’m successfully able to login but when I open the tenant app which is tenant1.sms.com I get the following error:
Target class [AuthLoginController] does not exist.
I have read and implemented the code from this link: https://tenancyforlaravel.com/docs/v3
Link for universal route in the below code: https://tenancyforlaravel.com/docs/v3/features/universal-routes
Following is my tenant route code:
Route::group(['middleware'=>['web',InitializeTenancyByDomain::class,PreventAccessFromCentralDomains::class] ],function () { Route::middleware(['universal'])->group(function () { Auth::routes(); }); Route::middleware(['auth'])->group(function () { Route::get('/', function () { return 'This is your multi-tenant application. The id of the current tenant is ' . tenant('id'); }); }); });
When I don’t use the Authentication, the above string is being diplayed
This is your multi-tenant application. The id of the current tenant is tenant1
Am I missing something for authentication in tenant?
Advertisement
Answer
I’ve found the solution. Just wanted to share in case someone else is looking for in the future or got stuck in a similar case.
Adding namespace namespace('App\Http\Controllers\')
in the below code will fix this problem.
Route::middleware(['universal'])->namespace('App\Http\Controllers\')->group(function () { Auth::routes(); });