JosephSilber / bouncer

Laravel Eloquent roles and abilities.
MIT License
3.45k stars 330 forks source link

Multiple Database Connection #606

Closed asyraf-loop closed 2 years ago

asyraf-loop commented 2 years ago

Hi to all maintainers and readers.

My Laravel apps is using 2 database connections. One is Postgres where the silber/bouncer is installed. Then one more is using MySQL. The reason for this is the apps is expanding then need to read other system database.

I have follow this step https://github.com/JosephSilber/bouncer#configuration

I add new model called BouncerAbility extends to Role and Ability, and BouncerRole extends to Role. then I add new connection for both of these models.

protected $connection = 'pgsql';

I also add the BouncerServiceProvider add the provider in config array. then I add

Bouncer::useAbilityModel(BouncerAbility::class); Bouncer::useRoleModel(BouncerRole::class);

in that provider.

But I still got the problem where the bouncer keep reading the MySQL database, not reading the Postgres database.

Any clues how to resolve this?

Thanks.

JosephSilber commented 2 years ago

Bouncer uses JOINs extensively, which means that all tables must reside in the same DB.

asyraf-loop commented 2 years ago

Bouncer uses JOINs extensively, which means that all tables must reside in the same DB.

Hi, thanks for the feedback.

I know the package use JOIN's, but the package is only installed at Postgres. Then it should not interacts with other db. The MySQL DB only use for reading only.

But I found a solution.

I remove the model, and also the configuration. Then I add the connection directly at vendor folder model file. Then it work.

protected $connection = 'pgsql';

silber/bouncer/src/Database/Ability.php silber/bouncer/src/Database/Role.php silber/bouncer/src/Database/HasRolesAndAbilities.php

maybe in future can add database connection type?