1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 19:54:04 +00:00

Add and test Tenant::currentOrFail()

This commit is contained in:
lukinovec 2022-10-10 15:12:04 +02:00
parent 0198a30413
commit 54a4258fa4
2 changed files with 20 additions and 0 deletions

View file

@ -10,6 +10,7 @@ use Stancl\Tenancy\Contracts;
use Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Database\TenantCollection;
use Stancl\Tenancy\Events;
use Stancl\Tenancy\Exceptions\TenancyNotInitializedException;
/**
* @property string|int $id
@ -50,6 +51,11 @@ class Tenant extends Model implements Contracts\Tenant
return tenant();
}
public static function currentOrFail(): Tenant
{
return static::current() ?? throw new TenancyNotInitializedException;
}
public function newCollection(array $models = []): TenantCollection
{
return new TenantCollection($models);