1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 09:34:05 +00:00

request data identification: add tenant_model_column configuration

This commit is contained in:
Samuel Štancl 2025-05-30 03:55:52 +02:00
parent 16171b1eaa
commit ec9b585e70
5 changed files with 61 additions and 20 deletions

View file

@ -176,6 +176,7 @@ class TenancyUrlGenerator extends UrlGenerator
{
if (tenant() && static::$passTenantParameterToRoutes) {
if (static::$defaultParameterNames) {
// todo0 this should be changed to something like static::$queryParameter and it should respect the configured tenant model column
return array_merge($parameters, ['tenant' => tenant()->getTenantKey()]);
} else {
return array_merge($parameters, [PathTenantResolver::tenantParameterName() => PathTenantResolver::tenantParameterValue(tenant())]);

View file

@ -20,7 +20,9 @@ class RequestDataTenantResolver extends Contracts\CachedTenantResolver
{
$payload = (string) $args[0];
if ($payload && $tenant = tenancy()->find($payload, withRelations: true)) {
$column = static::tenantModelColumn();
if ($payload && $tenant = tenancy()->find($payload, $column, withRelations: true)) {
return $tenant;
}
@ -34,6 +36,11 @@ class RequestDataTenantResolver extends Contracts\CachedTenantResolver
];
}
public static function tenantModelColumn(): string
{
return config('tenancy.identification.resolvers.' . static::class . '.tenant_model_column') ?? tenancy()->model()->getTenantKeyName();
}
/**
* Returns the name of the header used for identification, or null if header identification is disabled.
*/