A free open source IT asset/license management system
Hooked in RegenerateIdeHelperAfterMigrate to listener/events
snipe5c5d398f6469
diff --git a/app/Listeners/RegenerateIdeHelperAfterMigrate.php b/app/Listeners/RegenerateIdeHelperAfterMigrate.phpnew file mode 100644index 0000000000..070c73f354--- /dev/null+++ b/app/Listeners/RegenerateIdeHelperAfterMigrate.php@@ -0,0 +1,34 @@+<?php++namespace App\Listeners;++use Illuminate\Database\Events\MigrationsEnded;+use Illuminate\Support\Facades\Artisan;++/**+ * Regenerate the ide-helper model stub after each `php artisan migrate`+ * run so Larastan and the IDE see newly-added / renamed columns the+ * same day the migration lands. Production upgrades run+ * `migrate` without the dev dependency, so the class_exists guard+ * short-circuits before the artisan call that would otherwise throw+ * CommandNotFoundException and abort the upgrade.+ */+class RegenerateIdeHelperAfterMigrate+{+ public function handle(MigrationsEnded $event): void+ {+ if (! class_exists(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class)) {+ return;+ }++ try {+ Artisan::call('ide-helper:models', [+ '--write-mixin' => true,+ '--no-interaction' => true,+ ]);+ } catch (\Throwable) {+ // Dev tooling only. Never fail a migrate because the stub+ // couldn't be regenerated. Run manually to see errors.+ }+ }+}diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.phpindex 64a19f270b..48e6795386 100644--- a/app/Providers/EventServiceProvider.php+++ b/app/Providers/EventServiceProvider.php@@ -8,6 +8,8 @@ use App\Listeners\FulfillCheckoutRequestListener;use App\Listeners\LogFailedLogin;use App\Listeners\LogListener;use App\Listeners\LogSuccessfulLogin;+use App\Listeners\RegenerateIdeHelperAfterMigrate;+use Illuminate\Database\Events\MigrationsEnded;use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;class EventServiceProvider extends ServiceProvider@@ -25,6 +27,15 @@ class EventServiceProvider extends ServiceProvider'Illuminate\Auth\Events\Failed' => [LogFailedLogin::class,],++ // Dev-env only: regenerate the ide-helper model stub so+ // Larastan + IDE autocomplete track newly-added columns the+ // moment the migration finishes. No-op (via class_exists+ // guard inside the listener) on production boxes that don't+ // have barryvdh/laravel-ide-helper installed.+ MigrationsEnded::class => [+ RegenerateIdeHelperAfterMigrate::class,+ ],];/**