Created
June 14, 2025 12:33
-
-
Save brytey2k/478a9123c2128e10f0deffd86828d098 to your computer and use it in GitHub Desktop.
Simple work around for Laravel IDE Helper to generate field names of the various models in a multi-database multi-tenant application. The multi tenancy package used is https://github.com/archtechx/tenancy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Console\Commands; | |
use App\Models\Tenant; | |
use Illuminate\Console\Command; | |
use Illuminate\Support\Facades\Artisan; | |
/** | |
Simple work around for Laravel IDE Helper to generate field names of the various models | |
in a multi-database multi-tenant application. | |
The multi tenancy package used is https://github.com/archtechx/tenancy | |
*/ | |
class GenerateTenantIDEHelper extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'tenancy:ide-helper'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Generate IDE Helper for tenant databases'; | |
/** | |
* Execute the console command. | |
*/ | |
public function handle(): void | |
{ | |
$tenant = Tenant::first(); | |
if (!$tenant) { | |
$this->info('No tenants found. Exiting.'); | |
return; | |
} | |
$this->info('Generating IDE Helper for the default tenant.'); | |
tenancy()->initialize($tenant); | |
Artisan::call('ide-helper:generate'); | |
Artisan::call('ide-helper:meta'); | |
Artisan::call('ide-helper:models -W'); | |
tenancy()->end(); | |
$this->info('IDE Helper generation completed.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment