tenancy / multi-tenant

Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant
https://tenancy.dev
MIT License
2.56k stars 393 forks source link

Sanctum Implementation #947

Open monurakkaya opened 4 years ago

monurakkaya commented 4 years ago

Description of your feature

Sanctum integration guide



Information

Create a class which extends Laravel\Sanctum\PersonalAccessToken and apply the trait. In this example I've created Token class in App\Models\Auth

namespace App\Models\Auth\Token;

use Hyn\Tenancy\Traits\UsesTenantConnection;
use Laravel\Sanctum\PersonalAccessToken;

class Token extends PersonalAccessToken
{
    use UsesTenantConnection;

    protected $table = 'personal_access_tokens';

}

finally in your AppServiceProvider:

use Hyn\Tenancy\Events\Websites\Switched;
use App\Models\Auth\Token;
...
public function boot() 
{
    Event::listen(Switched::class, function (Switched $event) {
            Sanctum::usePersonalAccessTokenModel(Token::class);
    });
}

That's all.

jonquintero commented 4 years ago

Hi, Have you an example where I should use it ?

pansouk commented 2 years ago

Thank's dude. Very usefull.