PHP Class HipsterJazzbo\Landlord\TenantManager

Show file Open project: HipsterJazzbo/Landlord Class Usage Examples

Protected Properties

Property Type Description
$enabled boolean
$tenants Illuminate\Support\Collection

Public Methods

Method Description
__construct ( ) Landlord constructor.
addTenant ( string | Model $tenant, mixed | null $id = null ) Add a tenant to scope by.
applyTenantScopes ( Model $model ) Applies applicable tenant scopes to a model.
disable ( ) : void Disable scoping by tenantColumns.
enable ( ) : void Enable scoping by tenantColumns.
getTenants ( ) : Collection
hasTenant ( string | Model $tenant ) : boolean Whether a tenant is currently being scoped.
newModel ( Model $model ) Add tenant columns as needed to a new model instance before it is created.
newQueryWithoutTenants ( Model $model ) : Builder Get a new Eloquent Builder instance without any of the tenant scopes applied.
removeTenant ( string | Model $tenant ) Remove a tenant so that queries are no longer scoped by it.

Protected Methods

Method Description
getTenantKey ( string | Model $tenant ) : string Get the key for a tenant, either form a Model instance or a string.
modelTenants ( Model $model ) : Collection Get the tenantColumns that are actually applicable to the given model, in case they've been manually specified.

Method Details

__construct() public method

Landlord constructor.
public __construct ( )

addTenant() public method

Add a tenant to scope by.
public addTenant ( string | Model $tenant, mixed | null $id = null )
$tenant string | Illuminate\Database\Eloquent\Model
$id mixed | null

applyTenantScopes() public method

Applies applicable tenant scopes to a model.
public applyTenantScopes ( Model $model )
$model Illuminate\Database\Eloquent\Model

disable() public method

Disable scoping by tenantColumns.
public disable ( ) : void
return void

enable() public method

Enable scoping by tenantColumns.
public enable ( ) : void
return void

getTenantKey() protected method

Get the key for a tenant, either form a Model instance or a string.
protected getTenantKey ( string | Model $tenant ) : string
$tenant string | Illuminate\Database\Eloquent\Model
return string

getTenants() public method

public getTenants ( ) : Collection
return Illuminate\Support\Collection

hasTenant() public method

Whether a tenant is currently being scoped.
public hasTenant ( string | Model $tenant ) : boolean
$tenant string | Illuminate\Database\Eloquent\Model
return boolean

modelTenants() protected method

Get the tenantColumns that are actually applicable to the given model, in case they've been manually specified.
protected modelTenants ( Model $model ) : Collection
$model Illuminate\Database\Eloquent\Model
return Illuminate\Support\Collection

newModel() public method

Add tenant columns as needed to a new model instance before it is created.
public newModel ( Model $model )
$model Illuminate\Database\Eloquent\Model

newQueryWithoutTenants() public method

Get a new Eloquent Builder instance without any of the tenant scopes applied.
public newQueryWithoutTenants ( Model $model ) : Builder
$model Illuminate\Database\Eloquent\Model
return Illuminate\Database\Eloquent\Builder

removeTenant() public method

Remove a tenant so that queries are no longer scoped by it.
public removeTenant ( string | Model $tenant )
$tenant string | Illuminate\Database\Eloquent\Model

Property Details

$enabled protected property

protected bool $enabled
return boolean

$tenants protected property

protected Collection,Illuminate\Support $tenants
return Illuminate\Support\Collection