1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 11:14:04 +00:00

Fix #29 add Tenancy facade

This commit is contained in:
Samuel Štancl 2019-02-15 21:00:11 +01:00
parent 88d4e67516
commit 987c54f04e
4 changed files with 36 additions and 2 deletions

View file

@ -133,7 +133,7 @@ Read the [Storage driver](#storage-driver) section for more information.
## Obtaining a `TenantManager` instance
You can use the `tenancy()` and `tenant()` helpers to resolve `Stancl\Tenancy\TenantManager` out of the service container. These two helpers are exactly the same, the only reason there are two is nice syntax. `tenancy()->init()` sounds better than `tenant()->init()` and `tenant()->create()` sounds better than `tenancy()->create()`.
You can use the `tenancy()` and `tenant()` helpers to resolve `Stancl\Tenancy\TenantManager` out of the service container. These two helpers are exactly the same, the only reason there are two is nice syntax. `tenancy()->init()` sounds better than `tenant()->init()` and `tenant()->create()` sounds better than `tenancy()->create()`. **You may also use the `Tenancy` facade.**
### Creating a new tenant

View file

@ -37,7 +37,10 @@
"laravel": {
"providers": [
"Stancl\\Tenancy\\TenancyServiceProvider"
]
],
"aliases": {
"Tenancy": "Stancl\\Tenancy\\TenancyFacade"
}
}
}
}

13
src/TenancyFacade.php Normal file
View file

@ -0,0 +1,13 @@
<?php
namespace Stancl\Tenancy;
use Illuminate\Support\Facades\Facade;
class TenancyFacade extends Facade
{
protected static function getFacadeAccessor()
{
return TenantManager::class;
}
}

18
tests/FacadeTest.php Normal file
View file

@ -0,0 +1,18 @@
<?php
namespace Stancl\Tenancy\Tests;
use Stancl\Tenancy\TenancyFacade as Tenancy;
class FacadeTest extends TestCase
{
/** @test */
public function tenant_manager_can_be_accessed_using_the_Tenancy_facade()
{
tenancy()->put('foo', 'bar');
Tenancy::put('abc', 'xyz');
$this->assertSame('bar', Tenancy::get('foo'));
$this->assertSame('xyz', Tenancy::get('abc'));
}
}