Skip to content
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

Can't set $tenantColumns in model #99

Open
m3steele opened this issue Jun 5, 2018 · 0 comments
Open

Can't set $tenantColumns in model #99

m3steele opened this issue Jun 5, 2018 · 0 comments

Comments

@m3steele
Copy link

m3steele commented Jun 5, 2018

I am unable to get $tenantColumns to set/change the column used for tenant lookup. I want to use this to change the column used for tenant in one of my tables.

public $tenantColumns = ['id'];

I have logged what tenantColumn is set to by using

$tenants = Landlord::getTenants();

I have set my default $tenantColumns in config and I set the scoped tenant in middleware.

Here is my model (shortened for clarity) where i am trying to change the $tenantColumn.

<?php
namespace App\Models\Admin;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use HipsterJazzbo\Landlord\BelongsToTenants;

class company extends Model
{
    use SoftDeletes;
    use BelongsToTenants;
    public $tenantColumns = ['id'];

...

One thing possibly worth noting is I was unable to successfully addTenant without clearing booted models before addTennant was called.

My middle wear looks as follows:
Notice the addition of \Illuminate\Database\Eloquent\Model::clearBootedModels();
This was used as per instructions here: #64

I wonder is this same issue is affecting my ability to set $tenantColumns.

use Closure;
use Sentinel;
use HipsterJazzbo\Landlord\Facades\Landlord;
use Illuminate\Support\Facades\Auth;

class Tenancy
{

    public function handle($request, Closure $next)
    {

        if (!Sentinel::check()) {
            return redirect('login')->with('info', 'You must be logged in!');
        }
        else {

            \Illuminate\Database\Eloquent\Model::clearBootedModels();
            Landlord::addTenant('company_id', $request->user()->company_id);

            return $next($request);
        }
    }

}

Thanks for any assistance.

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

No branches or pull requests

1 participant