ollieread / multitenancy

A laravel package to provide multi-tenancy support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined method getTenantKey()

ilvalerione opened this issue · comments

Hello @ollieread thanks for this package. I think it's actually the best Laravel multitenancy package.

Inside your Eloquent global scope TenantOwnedScope there is a call to an unimplemented method getTenantKey() to retrieve the FK to the tenant table in the current eloquent model.

public function apply(Builder $builder, Model $model)
    {
        $builder->where(   $model->getTenantKey()    , '=', Multitenancy::tenant()->id);
    }

It's not implemented and you do not talk about it in documentation. For now I resolved implementing another trait called BelongsToTenant that use your original eloquent trait and implement getTenantKey() method.

trait BelongsToTenant
{
    use TenantOwned;

    public function getTenantKey()
    {
        return 'company_id';
    }
}

I think that tenant FK should be the same in any table and could be a good idea to implement this method yourself in TenantOwned trait to return a fixed value from config file for example.

if i understand something wrong i thank you if you want to help me.

@ilvalerione Apologies, I've been quite busy lately, I'll take a look at this as soon as I can. I plan to do some work on this as it is.

@ilvalerione My bad, you need to use the TenantOwned contract which I failed to mention in the documentation. It'll be fixed with the update.