Comments (13)
I don't have any experience with postgres, sorry
I don't know if it will be possible to override the boot methods, try that and remove the lines that give you problems
Another option would be to use softDeletes
trait (which I prefer), so those lines would never be called
from laravel-permission.
from laravel-permission.
it could work if i had limited number of databases and known database names. but tenants have database names based on id in UUID format
from laravel-permission.
Ok, add a custom Role/Permission model, and overwrite users
relation, set the real db name on the pivot tables(model_has_permissions
, model_has_roles
)
https://stackoverflow.com/questions/25142968/belongstomany-relationship-in-laravel-across-multiple-databases
laravel-permission/src/Models/Permission.php
Lines 71 to 80 in b6b9f4f
laravel-permission/src/Models/Role.php
Lines 80 to 89 in b6b9f4f
from laravel-permission.
unfortunately it didn't work. also, i tried method setConnection(CONNECTION_NAME) for users relationship, it didn't help either
Undefined table: 7 ERROR: relation "tenant_bcc6d892-a4db-40db-b271-fcc6eaaa1276.model_has_roles" does not exist
Connection: pgsql, SQL: delete from "tenant_bcc6d892-a4db-40db-b271-fcc6eaaa1276"."model_has_roles" where "tenant_bcc6d892-a4db-40db-b271-fcc6eaaa1276"."model_has_roles"."role_id" = 5
from laravel-permission.
is tenant_bcc6d892-a4db-40db-b271-fcc6eaaa1276
the connetion name or the db name??
I don't know how it works in postgres, in mysql it works without problems
from laravel-permission.
tenant_bcc6d892-a4db-40db-b271-fcc6eaaa1276 is db name.
$connection property for User is 'pgsql', $connection property for Role is 'tenant'
from laravel-permission.
Question:
can you use the scopes functionality?
because it uses relationships in the same way as users
https://spatie.be/laravel-permission/basic-usage#content-scopes
https://laravel.com/eloquent-relationships#defining-custom-intermediate-table-models
from laravel-permission.
i'll try to overwrite boot method of the trait, if laravel allows overwrite such type of methods
from laravel-permission.
thank you @parallels999 for help, finally i overwrote bootHasPermissions method and error's gone. other possible solutions didn't work out in my situation.
anyway, overwriting boot method is not the perfect solution, because any time i'll update app dependencies, i'll need to check if any important changes in HasPermissions boot method were added, and copy them to my boot
from laravel-permission.
also, schemas of model_has_roles and model_has_permissions tables use onDelete('cascade') method, that do the same as detach. that's why i'm not sure we really need to do the same on deletion
from laravel-permission.
use onDelete('cascade') method, that do the same as detach
Normally softDelete
is used, it's not the same
from laravel-permission.
that's right, i missed it
from laravel-permission.
Related Issues (20)
- [Lumen] Call to undefined method App\Models\User::canAny() HOT 6
- Default string length prerequisite conflict HOT 7
- There is no permission named `list-users` for guard `web`. HOT 2
- Cached permissions on multiple instances running on Octane / Kubernetes HOT 12
- Access to undeclared static property Spatie\Permission\PermissionRegistrar::$pivotPermission HOT 6
- Access to undeclared static property Spatie\Permission\PermissionRegistrar::$pivotRole HOT 1
- Trait "Spatie\Permission\Traits\HasRoles" not found in app/User.php HOT 10
- php artisan permission:show uuid error HOT 1
- Typo in docs HOT 1
- Base table or view not found: 1146 Table 'role_user' doesn't exist HOT 6
- for v6 - There is no role with ID `org_uuid` for guard `api` HOT 3
- team_id doesn't have a default value HOT 5
- assignRole and syncRoles fail for model with ulid type id HOT 2
- Documentation for v6/main unaccessible at spatie.be HOT 4
- Wrong octane event listener HOT 2
- Too much Role-Models loaded HOT 3
- Enums shouldn't be casted in the model HOT 8
- assignRole > getModel() > null
- Timestamps in migration for sql server HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-permission.