|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Staudenmeir\EloquentHasManyDeep; |
|
4
|
|
|
|
|
5
|
|
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; |
|
6
|
|
|
use Illuminate\Contracts\Support\DeferrableProvider; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
|
8
|
|
|
use Staudenmeir\EloquentHasManyDeep\IdeHelper\DeepRelationsHook; |
|
9
|
|
|
|
|
10
|
|
|
class EloquentHasManyDeepServiceProvider extends ServiceProvider implements DeferrableProvider |
|
11
|
|
|
{ |
|
12
|
4 |
|
public function boot(): void |
|
13
|
|
|
{ |
|
14
|
4 |
|
$this->publishConfig(); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
4 |
|
public function register(): void |
|
18
|
|
|
{ |
|
19
|
4 |
|
$this->registerConfig(); |
|
20
|
|
|
|
|
21
|
4 |
|
$this->registerIdeHelperHook(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
2 |
|
public function provides(): array |
|
25
|
|
|
{ |
|
26
|
2 |
|
return [ |
|
27
|
2 |
|
ModelsCommand::class, |
|
28
|
2 |
|
]; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
4 |
|
protected function registerIdeHelperHook(): void |
|
32
|
|
|
{ |
|
33
|
|
|
/** @var \Illuminate\Contracts\Config\Repository $config */ |
|
34
|
4 |
|
$config = $this->app->get('config'); |
|
35
|
|
|
|
|
36
|
4 |
|
if (!$config->get('eloquent-has-many-deep.ide_helper_enabled')) { |
|
37
|
2 |
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
2 |
|
$config->set('ide-helper.model_hooks', array_merge([ |
|
41
|
2 |
|
DeepRelationsHook::class, |
|
42
|
2 |
|
], $config->get('ide-helper.model_hooks', []))); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
4 |
|
protected function publishConfig(): void |
|
46
|
|
|
{ |
|
47
|
4 |
|
$this->publishes([ |
|
48
|
4 |
|
__DIR__ . '/../config/eloquent-has-many-deep.php' => config_path('eloquent-has-many-deep.php'), |
|
49
|
4 |
|
], 'eloquent-has-many-deep'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
4 |
|
protected function registerConfig(): void |
|
53
|
|
|
{ |
|
54
|
4 |
|
$this->mergeConfigFrom( |
|
55
|
4 |
|
__DIR__ . '/../config/eloquent-has-many-deep.php', |
|
56
|
4 |
|
'eloquent-has-many-deep', |
|
57
|
4 |
|
); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|