Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active tenant isn't available in executed migrations #1000

Open
sasokovacic opened this issue May 9, 2021 · 3 comments
Open

Active tenant isn't available in executed migrations #1000

sasokovacic opened this issue May 9, 2021 · 3 comments

Comments

@sasokovacic
Copy link

I can't get access to the active tenant (& db connection) when executing PHP artisan tenancy:migrate.
I need to change some data after migrating some structural changes


Information

  • hyn/multi-tenant version: 5.4
  • laravel version: 5.8
  • database driver and version: MySQL 8.0.19
  • webserver software and version: Apache/2.4.41
  • php version: 7.4.2
@nbayramberdiyev
Copy link

@sasokovacic Instead of running php artisan tenancy:migrate, please run php artisan tenancy:run migrate. Then you should be able to retrieve the current tenant in the migrations using app(\Hyn\Tenancy\Environment::class)->tenant();.

@stein-j
Copy link

stein-j commented Jul 25, 2021

@sasokovacic For the record there is another solution if you do not want to change your script and continue with tenancy:migrate. Please note this solution kind of a band-aid.

In your migration you can identify the tenant yourself by putting the following code in your migration:

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $environment = app(\Hyn\Tenancy\Environment::class);
        $tenantUuid = DB::connection()->getDatabaseName();
        $website = \Hyn\Tenancy\Models\Website::where('uuid', $tenantUuid)->firstOrFail();
        $environment->tenant($website);
       // Tenant is now identified like in a request 
    }

@sasokovacic
Copy link
Author

sasokovacic commented Aug 15, 2021

@stein-j Thanks. I'll try your solution, but it would stilll be really useful to have this feature built into the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants