File tree Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 42
42
"spatie/phpunit-snapshot-assertions" : " ^3 || ^4" ,
43
43
"vimeo/psalm" : " ^3.12"
44
44
},
45
+ "suggest" : {
46
+ "illuminate/events" : " Required for automatic helper generation (^6|^7|^8)."
47
+ },
45
48
"config" : {
46
49
"sort-packages" : true
47
50
},
Original file line number Diff line number Diff line change 278
278
*/
279
279
'additional_relation_types ' => [],
280
280
281
+ /*
282
+ |--------------------------------------------------------------------------
283
+ | Run artisan commands after migrations to generate model helpers
284
+ |--------------------------------------------------------------------------
285
+ |
286
+ | The specified commands should run after migrations are finished running.
287
+ |
288
+ */
289
+ 'post_migrate ' => [
290
+ // 'ide-helper:models --nowrite',
291
+ ],
292
+
281
293
];
Original file line number Diff line number Diff line change 15
15
use Barryvdh \LaravelIdeHelper \Console \GeneratorCommand ;
16
16
use Barryvdh \LaravelIdeHelper \Console \MetaCommand ;
17
17
use Barryvdh \LaravelIdeHelper \Console \ModelsCommand ;
18
+ use Barryvdh \LaravelIdeHelper \Listeners \GenerateModelHelper ;
19
+ use Illuminate \Console \Events \CommandFinished ;
18
20
use Illuminate \Contracts \Support \DeferrableProvider ;
21
+ use Illuminate \Database \Events \MigrationsEnded ;
19
22
use Illuminate \Foundation \Application ;
20
23
use Illuminate \Support \ServiceProvider ;
21
24
use Illuminate \View \Engines \EngineResolver ;
@@ -32,6 +35,13 @@ class IdeHelperServiceProvider extends ServiceProvider implements DeferrableProv
32
35
*/
33
36
public function boot ()
34
37
{
38
+ if ($ this ->app ['config ' ]->get ('ide-helper.post_migrate ' , [])) {
39
+ $ this ->app ['events ' ]->listen (CommandFinished::class, GenerateModelHelper::class);
40
+ $ this ->app ['events ' ]->listen (MigrationsEnded::class, function () {
41
+ GenerateModelHelper::$ shouldRun = true ;
42
+ });
43
+ }
44
+
35
45
if ($ this ->app ->has ('view ' )) {
36
46
$ viewPath = __DIR__ . '/../resources/views ' ;
37
47
$ this ->loadViewsFrom ($ viewPath , 'ide-helper ' );
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Barryvdh \LaravelIdeHelper \Listeners ;
4
+
5
+ use Illuminate \Console \Events \CommandFinished ;
6
+ use Illuminate \Contracts \Config \Repository as Config ;
7
+ use Illuminate \Contracts \Console \Kernel as Artisan ;
8
+
9
+ class GenerateModelHelper
10
+ {
11
+ /**
12
+ * Tracks whether we should run the models command on the CommandFinished event or not.
13
+ * Set to true by the MigrationsEnded event, needs to be cleared before artisan call to prevent infinite loop.
14
+ *
15
+ * @var bool
16
+ */
17
+ public static $ shouldRun = false ;
18
+
19
+ /** @var \Illuminate\Contracts\Console\Kernel */
20
+ protected $ artisan ;
21
+
22
+ /** @var \Illuminate\Contracts\Config\Repository */
23
+ protected $ config ;
24
+
25
+ /**
26
+ * @param \Illuminate\Contracts\Console\Kernel $artisan
27
+ * @param \Illuminate\Contracts\Config\Repository $config
28
+ */
29
+ public function __construct (Artisan $ artisan , Config $ config )
30
+ {
31
+ $ this ->artisan = $ artisan ;
32
+ $ this ->config = $ config ;
33
+ }
34
+
35
+ /**
36
+ * Handle the event.
37
+ *
38
+ * @param CommandFinished $event
39
+ */
40
+ public function handle (CommandFinished $ event )
41
+ {
42
+ if (!self ::$ shouldRun ) {
43
+ return ;
44
+ }
45
+
46
+ self ::$ shouldRun = false ;
47
+
48
+ foreach ($ this ->config ->get ('ide-helper.post_migrate ' , []) as $ command ) {
49
+ $ this ->artisan ->call ($ command , [], $ event ->output );
50
+ }
51
+ }
52
+ }
You can’t perform that action at this time.
0 commit comments