JosephSilber / bouncer

Laravel Eloquent roles and abilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple Database Connection

asyraf-loop opened this issue · comments

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.

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

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?