1 | <?php |
||
13 | class CategoriesServiceProvider extends ServiceProvider |
||
14 | { |
||
15 | /** |
||
16 | * The commands to be registered. |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $commands = [ |
||
21 | MigrateCommand::class => 'command.rinvex.categories.migrate', |
||
22 | PublishCommand::class => 'command.rinvex.categories.publish', |
||
23 | RollbackCommand::class => 'command.rinvex.categories.rollback', |
||
24 | ]; |
||
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | public function register() |
||
30 | { |
||
31 | // Merge config |
||
32 | $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.categories'); |
||
33 | |||
34 | // Bind eloquent models to IoC container |
||
35 | $this->app->singleton('rinvex.categories.category', $categoryModel = $this->app['config']['rinvex.categories.models.category']); |
||
|
|||
36 | $categoryModel === Category::class || $this->app->alias('rinvex.categories.category', Category::class); |
||
37 | |||
38 | // Register console commands |
||
39 | ! $this->app->runningInConsole() || $this->registerCommands(); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | public function boot() |
||
46 | { |
||
47 | // Load migrations |
||
48 | ! $this->app->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); |
||
49 | |||
50 | // Publish Resources |
||
51 | ! $this->app->runningInConsole() || $this->publishResources(); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Publish resources. |
||
56 | * |
||
57 | * @return void |
||
58 | */ |
||
59 | protected function publishResources(): void |
||
60 | { |
||
61 | $this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('rinvex.categories.php')], 'rinvex-categories-config'); |
||
62 | |||
63 | $timestamp = date('Y_m_d_His', time()); |
||
64 | |||
65 | $this->publishes([ |
||
66 | realpath( |
||
67 | __DIR__ . '/../../database/migrations/create_categories_table.php' |
||
68 | => database_path("/migrations/{$timestamp}_create_categories_table.php") |
||
69 | ), |
||
70 | realpath( |
||
71 | __DIR__ . '/../../database/migrations/create_categorizables_table.php' |
||
72 | => database_path("/migrations/{$timestamp}_create_categorizables_table.php") |
||
73 | ), |
||
74 | ], 'rinvex-categories-migrations'); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Register console commands. |
||
79 | * |
||
80 | * @return void |
||
92 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.