Is Filament V3 with compatible with tenancyforlaravel https://tenancyforlaravel.com/

i have i big issue with tenants connecting the database , i'm applying multi database architecture
22 Replies
TranceCode
TranceCode14mo ago
Hello bro, hey why don't you use only if you use separate databases it would be interesting, I am working on a Saas tenancy with separate databases but using a different package, specifically the one here https://tenancy.dev/
Tenancy
The multi tenant saas toolkit for Laravel
Tenancy allows you to easily scaffold a multi-tenant SaaS platform on top of the Laravel framework.
Hegabovic
HegabovicOP14mo ago
first time to hear about this package 😄 but all the recommendation goes for tenancywithlaravel and it provide SSO too 😄 , i will try this package you mentioned 😄 @Dennis Koch 😄
Dennis Koch
Dennis Koch14mo ago
So, what did you do so far to make Filament work with Tenancy For Laravel? Did you add the middlewares?
Hegabovic
HegabovicOP14mo ago
in database.php i added
'mysql_landlord' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('LANDLORD_DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],

'mysql_tenant' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'mysql_landlord' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('LANDLORD_DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],

'mysql_tenant' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Dennis Koch
Dennis Koch14mo ago
You need to add the Tenant Middlewares:
->middleware([
...
InitializeTenancyByDomain::class,
PreventAccessFromUnwantedDomains::class,
])
->middleware([
...
InitializeTenancyByDomain::class,
PreventAccessFromUnwantedDomains::class,
])
Hegabovic
HegabovicOP14mo ago
and in env i added that
NDLORD_DB_DATABASE=tenancy_landlord

DB_CONNECTION=mysql_landlord
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tenancy_tenants
DB_USERNAME=x
DB_PASSWORD=x
NDLORD_DB_DATABASE=tenancy_landlord

DB_CONNECTION=mysql_landlord
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tenancy_tenants
DB_USERNAME=x
DB_PASSWORD=x
this middleware doesnt exist PreventAccessFromUnwantedDomains the documentation is not clear on this topic 😅
Dennis Koch
Dennis Koch14mo ago
Sorry, I am using the alpha version of Tenancy but it should have a similar middleware that you need to add
Hegabovic
HegabovicOP14mo ago
pardon me , what is the alpha version ? do you mean the package called tenancy/tenancy
Dennis Koch
Dennis Koch14mo ago
There's a closed-access alpha for stancl/tenancy
Hegabovic
HegabovicOP14mo ago
hmmm i understand 😄
Dennis Koch
Dennis Koch14mo ago
You don't need it to work. The other middleware is the important part
Hegabovic
HegabovicOP14mo ago
ok, what about redirecting filament to read from the database of a specific tenant , can you help with that 😄 i mean the database configration in ( .env , database.php , tenancy.php)
Dennis Koch
Dennis Koch14mo ago
It's all about the middleware. If that one is missing, the tenancy package always assumes, you are on central connection
Hegabovic
HegabovicOP14mo ago
i will check it out 😄 in database.php
'mysql_landlord' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('LANDLORD_DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],

'mysql_tenant' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'mysql_landlord' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('LANDLORD_DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],

'mysql_tenant' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
in tenancy.php
'database' => [
'central_connection' => env('DB_CONNECTION', 'mysql_landlord'),

/**
* Connection used as a "template" for the dynamically created tenant database connection.
* Note: don't name your template connection tenant. That name is reserved by package.
*/
'template_tenant_connection' => 'mysql_tenant',
'database' => [
'central_connection' => env('DB_CONNECTION', 'mysql_landlord'),

/**
* Connection used as a "template" for the dynamically created tenant database connection.
* Note: don't name your template connection tenant. That name is reserved by package.
*/
'template_tenant_connection' => 'mysql_tenant',
in .env file
LANDLORD_DB_DATABASE=tenancy_landlord

DB_CONNECTION=mysql_landlord
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tenancy_tenants
DB_USERNAME=x
DB_PASSWORD=x
LANDLORD_DB_DATABASE=tenancy_landlord

DB_CONNECTION=mysql_landlord
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tenancy_tenants
DB_USERNAME=x
DB_PASSWORD=x
each tenant will have a database with his name is this configuration correct 😅 because it is reading from a weird connection called tenant witch i dont have
Dennis Koch
Dennis Koch14mo ago
That's the default connection name the package uses. Just rename your tenant connection. Or adjust the configuration of tenancy.php
Hegabovic
HegabovicOP14mo ago
i will check it out , thanks a lot 😄 the thing it is no dynamic , i want it to be changed dynamically with tenant database name , username , password 🤔
Dennis Koch
Dennis Koch14mo ago
It expects your databases to be in format central_name_number like mysql_1
Hegabovic
HegabovicOP14mo ago
but i want the tenant name to be in strings not numbers 😄 as it will be the also the database name
Dennis Koch
Dennis Koch14mo ago
You should maybe make the default work first before making things more complicated.
bogus
bogus11mo ago
Hello, The alpha version is the future v4 version, right? does stancl/tenancy "alpha" ( v4 ) work better with filament v3?
Dennis Koch
Dennis Koch11mo ago
No much difference I think apart from the public storage linking
Want results from more Discord servers?
Add your server