Skip to content

Commit

Permalink
Fix archtechx#29 add Tenancy facade
Browse files Browse the repository at this point in the history
  • Loading branch information
stancl committed Feb 15, 2019
1 parent 88d4e67 commit 987c54f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
"laravel": {
"providers": [
"Stancl\\Tenancy\\TenancyServiceProvider"
]
],
"aliases": {
"Tenancy": "Stancl\\Tenancy\\TenancyFacade"
}
}
}
}
13 changes: 13 additions & 0 deletions src/TenancyFacade.php
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions tests/FacadeTest.php
Original file line number Diff line number Diff line change
@@ -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'));
}
}

0 comments on commit 987c54f

Please sign in to comment.