GithubHelp home page GithubHelp logo

Comments (10)

masterix21 avatar masterix21 commented on June 27, 2024 1

Hi @dambridge, it's logic dependent.

If you have a separated users logic tenant by tenant, I can suggest to call php artisan tenants:artisan "passport:install".

If your users logic is included in your landlord, it isn't needed.

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024 1

Change it:
exec('cd ' . base_path() . ' && php artisan tenants:artisan "migrate --seed" --tenant=' . $tenant->id);

with:
exec('cd ' . base_path() . ' && php artisan tenants:artisan "migrate --seed --connection=tenant" --tenant=' . $tenant->id);

It's really important to specify the connection.

from laravel-multitenancy.

dambridge avatar dambridge commented on June 27, 2024

@masterix21 In my registration handler, I'm basically going to do this then:

exec('cd ' . base_path() . ' && php artisan tenants:artisan "migrate --seed" --tenant=' . $tenant->id);
exec('cd ' . base_path() . ' && php artisan tenants:artisan "passport:install" --tenant=' . $tenant->id);

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024

Yes, it seems ok What are your concerns?

PS: why don't you use: Artisan::call('tenants:artisan', [ "artisanCommand" => "passport:install", "--tenant" => $tenant->id ]);?

from laravel-multitenancy.

dambridge avatar dambridge commented on June 27, 2024

Per #23 , there are issues I had running Artisan directly.

Also, I just tried it but the Passport tables were still installed in the landlord database.

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024

Have you moved the passport migrations inside the tenant directory?

from laravel-multitenancy.

dambridge avatar dambridge commented on June 27, 2024

Yes. Well, the default migrations folder is the tenant directory, so that's where they are. Must be using the wrong connection somehow, but the other migrate command runs just fine. My Task:

<?php

namespace App\Tasks;

use Spatie\Multitenancy\Models\Tenant;
use Spatie\Multitenancy\Tasks\SwitchTenantTask;
use Laravel\Passport\Passport;

class PassportTask implements SwitchTenantTask
{
    public function __construct()
    {
        //
    }

    public function makeCurrent(Tenant $tenant): void
    {
        $this->setTenantPassport($tenant);
    }

    public function forgetCurrent(): void
    {
        $this->setTenantPassport();
    }

    protected function setTenantPassport(?Tenant $tenant = null): void
    {
        Passport::useTokenModel(TokenTenantAware::class);
        Passport::useClientModel(ClientTenantAware::class);
        Passport::useAuthCodeModel(AuthCodeTenantAware::class);
        Passport::usePersonalAccessClientModel(PersonalAccessClientTenantAware::class);
    }
}

from laravel-multitenancy.

dambridge avatar dambridge commented on June 27, 2024

Ah, hold up. This is the culprit methinks (in the default Passport migrations):

public function getConnection()
    {
        return config('passport.storage.database.connection');
    }

from laravel-multitenancy.

dambridge avatar dambridge commented on June 27, 2024

I published the Passport config and set the connection to 'tenant', migrations ran properly. However, NOW I'm getting an error when trying to create a token for the user:

Class 'App\Tasks\PersonalAccessClientTenantAware' not found

when trying

$token = $user->createToken('API')->accessToken;

from laravel-multitenancy.

dambridge avatar dambridge commented on June 27, 2024

Oh God. Nothing to see here. Forgot to import classes. Thanks @masterix21 .

from laravel-multitenancy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.