mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 18:04:03 +00:00
Add current() and currentOrFail() tenant methods (#970)
* Add and test `Tenant::current()` * Add and test `Tenant::currentOrFail()` * Fix code style (php-cs-fixer) * Update currentOrFail declaration Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com> * Change self return type to static Co-authored-by: PHP CS Fixer <phpcsfixer@example.com> Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
parent
76a3e269c8
commit
42dab2985a
2 changed files with 38 additions and 0 deletions
|
|
@ -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
|
||||
|
|
@ -45,6 +46,17 @@ class Tenant extends Model implements Contracts\Tenant
|
|||
return $this->getAttribute($this->getTenantKeyName());
|
||||
}
|
||||
|
||||
public static function current(): static|null
|
||||
{
|
||||
return tenant();
|
||||
}
|
||||
|
||||
/** @throws TenancyNotInitializedException */
|
||||
public static function currentOrFail(): static
|
||||
{
|
||||
return static::current() ?? throw new TenancyNotInitializedException;
|
||||
}
|
||||
|
||||
public function newCollection(array $models = []): TenantCollection
|
||||
{
|
||||
return new TenantCollection($models);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue