mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:04:04 +00:00
better defaults
This commit is contained in:
parent
6c5bde7d07
commit
1d42f33d34
6 changed files with 34 additions and 14 deletions
|
|
@ -238,11 +238,13 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
protected function mapRoutes()
|
protected function mapRoutes()
|
||||||
{
|
{
|
||||||
|
$this->app->booted(function () {
|
||||||
if (file_exists(base_path('routes/tenant.php'))) {
|
if (file_exists(base_path('routes/tenant.php'))) {
|
||||||
RouteFacade::namespace(static::$controllerNamespace)
|
RouteFacade::namespace(static::$controllerNamespace)
|
||||||
->middleware('tenant')
|
->middleware('tenant')
|
||||||
->group(base_path('routes/tenant.php'));
|
->group(base_path('routes/tenant.php'));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function makeTenancyMiddlewareHighestPriority()
|
protected function makeTenancyMiddlewareHighestPriority()
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,7 @@ return [
|
||||||
* Only relevant if you're using the domain or subdomain identification middleware.
|
* Only relevant if you're using the domain or subdomain identification middleware.
|
||||||
*/
|
*/
|
||||||
'central_domains' => [
|
'central_domains' => [
|
||||||
'127.0.0.1',
|
str(env('APP_URL'))->after('://')->before('/')->toString(),
|
||||||
'localhost',
|
|
||||||
],
|
],
|
||||||
|
|
||||||
'identification' => [
|
'identification' => [
|
||||||
|
|
@ -121,17 +120,28 @@ return [
|
||||||
* To configure their behavior, see the config keys below.
|
* To configure their behavior, see the config keys below.
|
||||||
*/
|
*/
|
||||||
'bootstrappers' => [
|
'bootstrappers' => [
|
||||||
|
// Basic Laravel features
|
||||||
Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper::class,
|
Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper::class,
|
||||||
|
Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper::class,
|
||||||
|
// Stancl\Tenancy\Bootstrappers\CacheTagsBootstrapper::class, // Alternative to PrefixCacheTenancyBootstrapper
|
||||||
Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper::class,
|
Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper::class,
|
||||||
Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper::class,
|
Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper::class,
|
||||||
|
// Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class, // Note: phpredis is needed
|
||||||
|
|
||||||
|
// Support for edge cases
|
||||||
|
Stancl\Tenancy\Bootstrappers\SessionTenancyBootstrapper::class,
|
||||||
Stancl\Tenancy\Bootstrappers\BatchTenancyBootstrapper::class,
|
Stancl\Tenancy\Bootstrappers\BatchTenancyBootstrapper::class,
|
||||||
// Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper::class,
|
|
||||||
|
// Configurable bootstrappers
|
||||||
// Stancl\Tenancy\Bootstrappers\RootUrlBootstrapper::class,
|
// Stancl\Tenancy\Bootstrappers\RootUrlBootstrapper::class,
|
||||||
// Stancl\Tenancy\Bootstrappers\UrlGeneratorBootstrapper::class,
|
// Stancl\Tenancy\Bootstrappers\UrlGeneratorBootstrapper::class,
|
||||||
|
// Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper::class, // Note: Queueing mail requires using QueueTenancyBootstrapper with $forceRefresh set to true
|
||||||
|
// Stancl\Tenancy\Bootstrappers\BroadcastingConfigBootstrapper::class,
|
||||||
|
// Stancl\Tenancy\Bootstrappers\BroadcastingChannelPrefixBootstrapper::class,
|
||||||
|
|
||||||
|
// Integration bootstrappers
|
||||||
// Stancl\Tenancy\Bootstrappers\Integrations\FortifyRouteTenancyBootstrapper::class,
|
// Stancl\Tenancy\Bootstrappers\Integrations\FortifyRouteTenancyBootstrapper::class,
|
||||||
// Stancl\Tenancy\Bootstrappers\SessionTenancyBootstrapper::class,
|
// Stancl\Tenancy\Bootstrappers\Integrations\ScoutTenancyBootstrapper::class,
|
||||||
// Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper::class, // Queueing mail requires using QueueTenancyBootstrapper with $forceRefresh set to true
|
|
||||||
// Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class, // Note: phpredis is needed
|
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use Illuminate\Database\DatabaseManager;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Contracts\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
|
||||||
|
// todo add docblock
|
||||||
class BatchTenancyBootstrapper implements TenancyBootstrapper
|
class BatchTenancyBootstrapper implements TenancyBootstrapper
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ use Illuminate\Support\Facades\Cache;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Contracts\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
|
||||||
|
// todo@rename some bootstrappers end in TenancyBootstrapper and others don't - make this consistent or make the difference clear
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* todo@name rename?
|
* todo@name rename?
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,19 @@ class SessionTenancyBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
public function bootstrap(Tenant $tenant): void
|
public function bootstrap(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
|
if ($this->config->get('session.driver') === 'database') {
|
||||||
$this->resetDatabaseHandler();
|
$this->resetDatabaseHandler();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function revert(): void
|
public function revert(): void
|
||||||
{
|
{
|
||||||
|
if ($this->config->get('session.driver') === 'database') {
|
||||||
// When ending tenancy, this runs *before* the DatabaseTenancyBootstrapper, so DB tenancy
|
// When ending tenancy, this runs *before* the DatabaseTenancyBootstrapper, so DB tenancy
|
||||||
// is still bootstrapped. For that reason, we have to explicitly use the central connection
|
// is still bootstrapped. For that reason, we have to explicitly use the central connection
|
||||||
$this->resetDatabaseHandler(config('tenancy.database.central_connection'));
|
$this->resetDatabaseHandler(config('tenancy.database.central_connection'));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function resetDatabaseHandler(string $defaultConnection = null): void
|
protected function resetDatabaseHandler(string $defaultConnection = null): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
'--realpath' => true,
|
'--realpath' => true,
|
||||||
'--force' => true,
|
'--force' => true,
|
||||||
],
|
],
|
||||||
|
'tenancy.central_domains' => ['localhost', '127.0.0.1'],
|
||||||
'tenancy.bootstrappers' => [
|
'tenancy.bootstrappers' => [
|
||||||
DatabaseTenancyBootstrapper::class,
|
DatabaseTenancyBootstrapper::class,
|
||||||
FilesystemTenancyBootstrapper::class,
|
FilesystemTenancyBootstrapper::class,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue