tenancy.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. declare(strict_types=1);
  3. use App\Models\Tenant;
  4. use Stancl\Tenancy\Database\Models\Domain;
  5. return [
  6. 'tenant_model' => Tenant::class,
  7. 'id_generator' => Stancl\Tenancy\UUIDGenerator::class,
  8. 'domain_model' => Domain::class,
  9. /**
  10. * The list of domains hosting your central app.
  11. *
  12. * Only relevant if you're using the domain or subdomain identification middleware.
  13. */
  14. 'central_domains' => [
  15. '127.0.0.1',
  16. 'localhost',
  17. ],
  18. /**
  19. * Tenancy bootstrappers are executed when tenancy is initialized.
  20. * Their responsibility is making Laravel features tenant-aware.
  21. *
  22. * To configure their behavior, see the config keys below.
  23. */
  24. 'bootstrappers' => [
  25. Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper::class,
  26. Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper::class,
  27. Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper::class,
  28. Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper::class,
  29. Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class, // Note: phpredis is needed
  30. ],
  31. /**
  32. * Database tenancy config. Used by DatabaseTenancyBootstrapper.
  33. */
  34. 'database' => [
  35. 'central_connection' => env('CENTRAL_DB_CONNECTION', 'central'),
  36. /**
  37. * Connection used as a "template" for the dynamically created tenant database connection.
  38. * Note: don't name your template connection tenant. That name is reserved by package.
  39. */
  40. 'template_tenant_connection' => env('CENTRAL_DB_CONNECTION', 'central'),
  41. /**
  42. * Tenant database names are created like this:
  43. * prefix + tenant_id + suffix.
  44. */
  45. 'prefix' => 'tenant_',
  46. 'suffix' => '',
  47. /**
  48. * TenantDatabaseManagers are classes that handle the creation & deletion of tenant databases.
  49. */
  50. 'managers' => [
  51. 'sqlite' => Stancl\Tenancy\TenantDatabaseManagers\SQLiteDatabaseManager::class,
  52. 'mysql' => Stancl\Tenancy\TenantDatabaseManagers\MySQLDatabaseManager::class,
  53. 'pgsql' => Stancl\Tenancy\TenantDatabaseManagers\PostgreSQLDatabaseManager::class,
  54. /**
  55. * Use this database manager for MySQL to have a DB user created for each tenant database.
  56. * You can customize the grants given to these users by changing the $grants property.
  57. */
  58. // 'mysql' => Stancl\Tenancy\TenantDatabaseManagers\PermissionControlledMySQLDatabaseManager::class,
  59. /**
  60. * Disable the pgsql manager above, and enable the one below if you
  61. * want to separate tenant DBs by schemas rather than databases.
  62. */
  63. // 'pgsql' => Stancl\Tenancy\TenantDatabaseManagers\PostgreSQLSchemaManager::class, // Separate by schema instead of database
  64. ],
  65. ],
  66. /**
  67. * Cache tenancy config. Used by CacheTenancyBootstrapper.
  68. *
  69. * This works for all Cache facade calls, cache() helper
  70. * calls and direct calls to injected cache stores.
  71. *
  72. * Each key in cache will have a tag applied on it. This tag is used to
  73. * scope the cache both when writing to it and when reading from it.
  74. *
  75. * You can clear cache selectively by specifying the tag.
  76. */
  77. 'cache' => [
  78. 'tag_base' => 'tenant', // This tag_base, followed by the tenant_id, will form a tag that will be applied on each cache call.
  79. ],
  80. /**
  81. * Filesystem tenancy config. Used by FilesystemTenancyBootstrapper.
  82. * https://tenancyforlaravel.com/docs/v3/tenancy-bootstrappers/#filesystem-tenancy-boostrapper.
  83. */
  84. 'filesystem' => [
  85. /**
  86. * Each disk listed in the 'disks' array will be suffixed by the suffix_base, followed by the tenant_id.
  87. */
  88. 'suffix_base' => 'tenant',
  89. 'disks' => [
  90. 'local',
  91. 'public',
  92. // 's3',
  93. ],
  94. /**
  95. * Use this for local disks.
  96. *
  97. * See https://tenancyforlaravel.com/docs/v3/tenancy-bootstrappers/#filesystem-tenancy-boostrapper
  98. */
  99. 'root_override' => [
  100. // Disks whose roots should be overridden after storage_path() is suffixed.
  101. 'local' => '%storage_path%/app/',
  102. 'public' => '%storage_path%/app/public/',
  103. ],
  104. /**
  105. * Should storage_path() be suffixed.
  106. *
  107. * Note: Disabling this will likely break local disk tenancy. Only disable this if you're using an external file storage service like S3.
  108. *
  109. * For the vast majority of applications, this feature should be enabled. But in some
  110. * edge cases, it can cause issues (like using Passport with Vapor - see #196), so
  111. * you may want to disable this if you are experiencing these edge case issues.
  112. */
  113. 'suffix_storage_path' => true,
  114. /**
  115. * By default, asset() calls are made multi-tenant too. You can use global_asset() and mix()
  116. * for global, non-tenant-specific assets. However, you might have some issues when using
  117. * packages that use asset() calls inside the tenant app. To avoid such issues, you can
  118. * disable asset() helper tenancy and explicitly use tenant_asset() calls in places
  119. * where you want to use tenant-specific assets (product images, avatars, etc).
  120. */
  121. 'asset_helper_tenancy' => true,
  122. ],
  123. /**
  124. * Redis tenancy config. Used by RedisTenancyBootstrapper.
  125. *
  126. * Note: You need phpredis to use Redis tenancy.
  127. *
  128. * Note: You don't need to use this if you're using Redis only for cache.
  129. * Redis tenancy is only relevant if you're making direct Redis calls,
  130. * either using the Redis facade or by injecting it as a dependency.
  131. */
  132. 'redis' => [
  133. 'prefix_base' => 'tenant', // Each key in Redis will be prepended by this prefix_base, followed by the tenant id.
  134. 'prefixed_connections' => [ // Redis connections whose keys are prefixed, to separate one tenant's keys from another.
  135. 'cache',
  136. ],
  137. ],
  138. /**
  139. * Features are classes that provide additional functionality
  140. * not needed for tenancy to be bootstrapped. They are run
  141. * regardless of whether tenancy has been initialized.
  142. *
  143. * See the documentation page for each class to
  144. * understand which ones you want to enable.
  145. */
  146. 'features' => [
  147. // Stancl\Tenancy\Features\UserImpersonation::class,
  148. Stancl\Tenancy\Features\TelescopeTags::class,
  149. // Stancl\Tenancy\Features\UniversalRoutes::class,
  150. // Stancl\Tenancy\Features\TenantConfig::class, // https://tenancyforlaravel.com/docs/v3/features/tenant-config
  151. // Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancyforlaravel.com/docs/v3/features/cross-domain-redirect
  152. // Stancl\Tenancy\Features\ViteBundler::class,
  153. ],
  154. /**
  155. * Should tenancy routes be registered.
  156. *
  157. * Tenancy routes include tenant asset routes. By default, this route is
  158. * enabled. But it may be useful to disable them if you use external
  159. * storage (e.g. S3 / Dropbox) or have a custom asset controller.
  160. */
  161. 'routes' => true,
  162. /**
  163. * Parameters used by the tenants:migrate command.
  164. */
  165. 'migration_parameters' => [
  166. '--force' => true, // This needs to be true to run migrations in production.
  167. '--path' => [database_path('migrations/tenant')],
  168. '--realpath' => true,
  169. ],
  170. /**
  171. * Parameters used by the tenants:seed command.
  172. */
  173. 'seeder_parameters' => [
  174. '--class' => 'DatabaseSeeder', // root seeder class
  175. // '--force' => true,
  176. ],
  177. /**
  178. * init Tenancy middleware.
  179. * domain or requestData
  180. *
  181. */
  182. 'init_tenant_middleware' => env('INIT_TENANT_MIDDLEWARE', 'domain')
  183. ];