Coder Social home page Coder Social logo

Comments (13)

parallels999 avatar parallels999 commented on August 16, 2024 1

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.

parallels999 avatar parallels999 commented on August 16, 2024

#2095 (comment)

from laravel-permission.

Ivan3008 avatar Ivan3008 commented on August 16, 2024

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.

parallels999 avatar parallels999 commented on August 16, 2024

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

public function users(): BelongsToMany
{
return $this->morphedByMany(
getModelForGuard($this->attributes['guard_name'] ?? config('auth.defaults.guard')),
'model',
config('permission.table_names.model_has_permissions'),
app(PermissionRegistrar::class)->pivotPermission,
config('permission.column_names.model_morph_key')
);
}

public function users(): BelongsToMany
{
return $this->morphedByMany(
getModelForGuard($this->attributes['guard_name'] ?? config('auth.defaults.guard')),
'model',
config('permission.table_names.model_has_roles'),
app(PermissionRegistrar::class)->pivotRole,
config('permission.column_names.model_morph_key')
);
}

from laravel-permission.

Ivan3008 avatar Ivan3008 commented on August 16, 2024

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.

parallels999 avatar parallels999 commented on August 16, 2024

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.

Ivan3008 avatar Ivan3008 commented on August 16, 2024

tenant_bcc6d892-a4db-40db-b271-fcc6eaaa1276 is db name.

$connection property for User is 'pgsql', $connection property for Role is 'tenant'

from laravel-permission.

parallels999 avatar parallels999 commented on August 16, 2024

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.

Ivan3008 avatar Ivan3008 commented on August 16, 2024

i'll try to overwrite boot method of the trait, if laravel allows overwrite such type of methods

from laravel-permission.

Ivan3008 avatar Ivan3008 commented on August 16, 2024

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.

Ivan3008 avatar Ivan3008 commented on August 16, 2024

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.

parallels999 avatar parallels999 commented on August 16, 2024

use onDelete('cascade') method, that do the same as detach

Normally softDelete is used, it's not the same

from laravel-permission.

Ivan3008 avatar Ivan3008 commented on August 16, 2024

that's right, i missed it

from laravel-permission.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.