Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ricardov03/dfc5cb865f5fa864e86481a9be517d70 to your computer and use it in GitHub Desktop.

Select an option

Save ricardov03/dfc5cb865f5fa864e86481a9be517d70 to your computer and use it in GitHub Desktop.
This sample is how to execute Artisan Commands with Spatie Laravel-multitenancy with Laravel APP_ENV environment set to 'production'.
<?php
// This sample present the same command. But the one executed in 'local' doesn't work if Laravel APP_ENV is set to production.
if(app()->environment('local'))
Artisan::call('tenants:artisan "migrate --database=tenant --seed" -q --tenant=' . $customer->getkey());
// Is necessary to understand the --force flag is set on the artisanCommand variable and NOT in the global scoped executed command.
// This is because the artisanCommand on the tenants:artisan defines the final artisan command to execute on each tenant.
// For more information related to Artisan Commands Production environments check this [article](https://divinglaravel.com/the-problem-behind-undefined-constant-stdin-when-running-laravel-artisan-command-programmatically) from Mohammed Said.
if(app()->environment('production'))
Artisan::call('tenants:artisan', [
'artisanCommand' => 'migrate --seed --force',
'--tenant' => $customer->getkey()
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment