Hi i use laravel 10 with tenancy for laravel, i have two connection, and for my central database i use users model its fine with default connection, but for tenancy i use second connection to retrive data from server ( but not everytime , here i use both conn ) which second connection have the accounts table ( game database), and i want to make session from account. In reast everything is fine but i dont know how to change the providers model to switch from users to accounts..
I want to use for example in breeze auth package account model not users..
I did this but its work just if i make login ( succesfully ) but when i try to do logout ( just logout i tried ), he tried to select from users model.. So i’m sure i did something wrong.. or maybe everything is wrong
i change the config/auth and i created an middleware (declare in kernel.php for tenant group):
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'tenant' => [
'driver' => 'session',
'provider' => 'accounts',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => AppModelsUser::class,
],
'accounts' => [
'driver' => 'eloquent',
'model' => AppModelsTenantAccount::class,
],
],
class SwitchAuthModel
{
/**
* Handle an incoming request.
*
* @param Closure(IlluminateHttpRequest): (SymfonyComponentHttpFoundationResponse) $next
*/
public function handle(Request $request, Closure $next): Response
{
config(['auth.guards.web' => config('auth.guards.tenant')]);
return $next($request);
}
}
Thanks in advance.
2
Answers
I fixed..
in my InitializeTenancyByDomain i put this in __construct
and you need to create a new auth middleware for tenant.
Best regards, Alex.
I solve this by making a custom login for the tenant users.
auth.php
Helper function that returns guard tenant or web
Custom Login Controller Method For Tenant Users
For tenant users just add a guard with auth middleware like auth:tenant