1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 11:14:04 +00:00

[4.x] Cleanup (#1317)

* cleanup, resolve todos, add immediate todos

* Improve path_identification_middleware docblock

* rename leave() method in tests

* wip fix hardcoded values making assumptions about the parameters used in routing

* defaultParameterNames

* fix CreatesDatabaseUsers return values

* $tenant -> tenant()

* resolve more todos

* make comment block a complete block

* Correct useTenantRoutesInFortify(), delete unused import

* test fixes

* remove todos

* remove JobPipeline todo

* simplify comment example

* remove todo

* fix VERSION_PREFIX in queue.yml

---------

Co-authored-by: lukinovec <lukinovec@gmail.com>
This commit is contained in:
Samuel Štancl 2025-02-20 20:49:09 +01:00 committed by GitHub
parent eac88dcc2a
commit 657e165cc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 148 additions and 182 deletions

View file

@ -145,24 +145,19 @@ class TenancyServiceProvider extends ServiceProvider
*/
protected function overrideUrlInTenantContext(): void
{
/**
* Import your tenant model!
*
* \Stancl\Tenancy\Bootstrappers\RootUrlBootstrapper::$rootUrlOverride = function (Tenant $tenant, string $originalRootUrl) {
* $tenantDomain = $tenant instanceof \Stancl\Tenancy\Contracts\SingleDomainTenant
* ? $tenant->domain
* : $tenant->domains->first()->domain;
*
* $scheme = str($originalRootUrl)->before('://');
*
* // If you're using domain identification:
* return $scheme . '://' . $tenantDomain . '/';
*
* // If you're using subdomain identification:
* $originalDomain = str($originalRootUrl)->after($scheme . '://');
* return $scheme . '://' . $tenantDomain . '.' . $originalDomain . '/';
* };
*/
// \Stancl\Tenancy\Bootstrappers\RootUrlBootstrapper::$rootUrlOverride = function (Tenant $tenant, string $originalRootUrl) {
// $tenantDomain = $tenant instanceof \Stancl\Tenancy\Contracts\SingleDomainTenant
// ? $tenant->domain
// : $tenant->domains->first()->domain;
// $scheme = str($originalRootUrl)->before('://');
//
// // If you're using domain identification:
// return $scheme . '://' . $tenantDomain . '/';
//
// // If you're using subdomain identification:
// $originalDomain = str($originalRootUrl)->after($scheme . '://');
// return $scheme . '://' . $tenantDomain . '.' . $originalDomain . '/';
// };
}
public function register()
@ -178,32 +173,17 @@ class TenancyServiceProvider extends ServiceProvider
$this->makeTenancyMiddlewareHighestPriority();
$this->overrideUrlInTenantContext();
/**
* Include soft deleted resources in synced resource queries.
*
* ResourceSyncing\Listeners\UpdateOrCreateSyncedResource::$scopeGetModelQuery = function (Builder $query) {
* if ($query->hasMacro('withTrashed')) {
* $query->withTrashed();
* }
* };
*/
// // Include soft deleted resources in synced resource queries.
// ResourceSyncing\Listeners\UpdateOrCreateSyncedResource::$scopeGetModelQuery = function (Builder $query) {
// if ($query->hasMacro('withTrashed')) {
// $query->withTrashed();
// }
// };
/**
* To make Livewire v3 work with Tenancy, make the update route universal.
*
* Livewire::setUpdateRoute(function ($handle) {
* return RouteFacade::post('/livewire/update', $handle)->middleware(['web', 'universal']);
* });
*/
// if (InitializeTenancyByRequestData::inGlobalStack()) {
// FortifyRouteBootstrapper::$fortifyHome = 'dashboard';
// TenancyUrlGenerator::$prefixRouteNames = false;
// }
if (tenancy()->globalStackHasMiddleware(config('tenancy.identification.path_identification_middleware'))) {
TenancyUrlGenerator::$prefixRouteNames = true;
}
// // To make Livewire v3 work with Tenancy, make the update route universal.
// Livewire::setUpdateRoute(function ($handle) {
// return RouteFacade::post('/livewire/update', $handle)->middleware(['web', 'universal', \Stancl\Tenancy::defaultMiddleware()]);
// });
}
protected function bootEvents()
@ -228,10 +208,7 @@ class TenancyServiceProvider extends ServiceProvider
->group(base_path('routes/tenant.php'));
}
// Delete this condition when using route-level path identification
if (tenancy()->globalStackHasMiddleware(config('tenancy.identification.path_identification_middleware'))) {
$this->cloneRoutes();
}
// $this->cloneRoutes();
});
}
@ -245,16 +222,13 @@ class TenancyServiceProvider extends ServiceProvider
/** @var CloneRoutesAsTenant $cloneRoutes */
$cloneRoutes = $this->app->make(CloneRoutesAsTenant::class);
/**
* You can provide a closure for cloning a specific route, e.g.:
* $cloneRoutes->cloneUsing('welcome', function () {
* RouteFacade::get('/tenant-welcome', fn () => 'Current tenant: ' . tenant()->getTenantKey())
* ->middleware(['universal', InitializeTenancyByPath::class])
* ->name('tenant.welcome');
* });
*
* To see the default behavior of cloning the universal routes, check out the cloneRoute() method in CloneRoutesAsTenant.
*/
// // You can provide a closure for cloning a specific route, e.g.:
// $cloneRoutes->cloneUsing('welcome', function () {
// RouteFacade::get('/tenant-welcome', fn () => 'Current tenant: ' . tenant()->getTenantKey())
// ->middleware(['universal', InitializeTenancyByPath::class])
// ->name('tenant.welcome');
// });
// // To see the default behavior of cloning the universal routes, check out the cloneRoute() method in CloneRoutesAsTenant.
$cloneRoutes->handle();
}

View file

@ -91,7 +91,7 @@ return [
/**
* Identification middleware tenancy recognizes as path identification middleware.
*
* This is used during determining whether whether a path identification is used
* This is used for determining if a path identification middleware is used
* during operations specific to path identification, e.g. forgetting the tenant parameter in ForgetTenantParameter.
*
* If you're using a custom path identification middleware, add it here.
@ -118,6 +118,7 @@ return [
Resolvers\PathTenantResolver::class => [
'tenant_parameter_name' => 'tenant',
'tenant_model_column' => null, // null = tenant key
'tenant_route_name_prefix' => null, // null = 'tenant.'
'allowed_extra_model_columns' => [], // used with binding route fields
'cache' => false,
@ -130,8 +131,6 @@ return [
'cache_store' => null, // null = default
],
],
// todo@docs update integration guides to use Stancl\Tenancy::defaultMiddleware()
],
/**
@ -215,7 +214,14 @@ return [
// 'pgsql' => Stancl\Tenancy\Database\TenantDatabaseManagers\PermissionControlledPostgreSQLSchemaManager::class, // Also permission controlled
],
// todo@docblock
/*
* Drop tenant databases when `php artisan migrate:fresh` is used.
* You may want to use this locally since deleting tenants only
* deletes their databases when they're deleted individually, not
* when the records are mass deleted from the database.
*
* Note: This overrides the default MigrateFresh command.
*/
'drop_tenant_databases_on_migrate_fresh' => false,
],
@ -320,7 +326,6 @@ return [
*/
'url_override' => [
// Note that the local disk you add must exist in the tenancy.filesystem.root_override config
// todo@v4 Rename url_override to something that describes the config key better
'public' => 'public-%tenant%',
],
@ -356,7 +361,7 @@ return [
* leave asset() helper tenancy disabled and explicitly use tenant_asset() calls in places
* where you want to use tenant-specific assets (product images, avatars, etc).
*/
'asset_helper_tenancy' => false, // todo@rename asset_helper_override?
'asset_helper_override' => false,
],
/**