Skip to content

A new way to use a model as a Tenant and Landlord. #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mckaragulle
Copy link

Option 3: Using a model as both tenant and landlord

It automatically detects when logged in as a Tenant or Landlord. It automatically sets the database connection name.

With this method, the database connection error that occurs when matching roles and permissions while using the Laravel spatie/permission package is also prevented.

With this method, you do not need to use different Models that use the same table name on the Landlord and Tenant sides.

You can use this instead of Option 2.

To accomplish that use trait UsesBothConnection

Here's an example:

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Spatie\Permission\Models\Role as SpatieRole;
use Spatie\Multitenancy\Models\Concerns\UsesBothConnection;

class Role extends SpatieRole
{
    use HasFactory;
    use UsesBothConnection;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant