1
|
|
|
<?php |
2
|
|
|
namespace crocodicstudio\crudbooster; |
3
|
|
|
|
4
|
|
|
use crocodicstudio\crudbooster\CBCoreModule\CbUser; |
5
|
|
|
use crocodicstudio\crudbooster\CBCoreModule\Facades\CbRouter; |
6
|
|
|
use crocodicstudio\crudbooster\Modules\ApiGeneratorModule\CbApiGeneratorServiceProvider; |
7
|
|
|
use crocodicstudio\crudbooster\Modules\AuthModule\CbAuthServiceProvider; |
8
|
|
|
use crocodicstudio\crudbooster\Modules\EmailTemplates\CbEmailTemplatesServiceProvider; |
9
|
|
|
use crocodicstudio\crudbooster\Modules\FileManagerModule\CbFileManagerServiceProvider; |
10
|
|
|
use crocodicstudio\crudbooster\Modules\LogsModule\CbLogsServiceProvider; |
11
|
|
|
use crocodicstudio\crudbooster\Modules\MenuModule\CbMenuServiceProvider; |
12
|
|
|
use crocodicstudio\crudbooster\Modules\ModuleGenerator\CbModulesGeneratorServiceProvider; |
13
|
|
|
use crocodicstudio\crudbooster\Modules\NotificationsModule\CbNotificationsServiceProvider; |
14
|
|
|
use crocodicstudio\crudbooster\Modules\PrivilegeModule\CbPrivilegesServiceProvider; |
15
|
|
|
use crocodicstudio\crudbooster\Modules\SettingModule\CbSettingsServiceProvider; |
16
|
|
|
use crocodicstudio\crudbooster\Modules\StatisticModule\CbStatisticsServiceProvider; |
17
|
|
|
use Illuminate\Support\ServiceProvider; |
18
|
|
|
use crocodicstudio\crudbooster\commands\InstallationCommand; |
19
|
|
|
use Illuminate\Foundation\AliasLoader; |
20
|
|
|
|
21
|
|
|
class CRUDBoosterServiceProvider extends ServiceProvider |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Bootstrap the application services. |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
public function boot() |
30
|
|
|
{ |
31
|
|
|
$this->loadViewsFrom(__DIR__.'/views', 'crudbooster'); |
32
|
|
|
$this->publishes([__DIR__.'/CBCoreModule/configs/crudbooster.php' => config_path('crudbooster.php')], 'cb_config'); |
33
|
|
|
$this->publishes([__DIR__.'/localization' => resource_path('lang')], 'cb_localization'); |
34
|
|
|
|
35
|
|
|
/* Integrate LFM to CRUDBooster */ |
36
|
|
|
$this->publishes([ |
37
|
|
|
__DIR__.'/laravel-filemanager' => base_path('vendor/unisharp/laravel-filemanager'), |
38
|
|
|
], 'cb_lfm'); |
39
|
|
|
|
40
|
|
|
$this->publishes([ |
41
|
|
|
__DIR__.'/laravel-filemanager/public' => public_path('vendor/laravel-filemanager'), |
42
|
|
|
], 'cb_lfm'); |
43
|
|
|
|
44
|
|
|
$this->publishes([ |
45
|
|
|
__DIR__.'/laravel-filemanager/src/config/lfm.php' => config_path('lfm.php'), |
46
|
|
|
], 'cb_lfm'); |
47
|
|
|
|
48
|
|
|
$this->publishes([ |
49
|
|
|
__DIR__.'/laravel-filemanager/src/views/script.blade.php' => resource_path('views/vendor/laravel-filemanager/script.blade.php'), |
50
|
|
|
], 'cb_lfm'); |
51
|
|
|
|
52
|
|
|
$this->publishes([ |
53
|
|
|
__DIR__.'/CBCoreModule/publieshed_files/readme.txt' => resource_path('views/vendor/crudbooster/type_components/readme.txt'), |
54
|
|
|
], 'cb_type_components'); |
55
|
|
|
|
56
|
|
|
if (! file_exists(app_path('Http/Controllers/AdminUsersController.php'))) { |
57
|
|
|
$this->publishes([__DIR__.'/CBCoreModule/publieshed_files/AdminUsersController.php' => app_path('Http/Controllers/AdminUsersController.php')], 'cb_user_controller'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
$this->defineValidationRules(); |
62
|
|
|
$this->loadRoutesFrom( __DIR__.'/routes.php'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Register the application services. |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function register() |
71
|
|
|
{ |
72
|
|
|
$this->mergeConfigFrom(__DIR__.'/configs/crudbooster.php', 'crudbooster'); |
73
|
|
|
|
74
|
|
|
$this->app->singleton('crudbooster', function () { |
75
|
|
|
return true; |
76
|
|
|
}); |
77
|
|
|
|
78
|
|
|
$this->commands(InstallationCommand::class); |
79
|
|
|
|
80
|
|
|
$this->defineAuthGuard(); |
81
|
|
|
|
82
|
|
|
$this->app->register('Barryvdh\DomPDF\ServiceProvider'); |
83
|
|
|
$this->app->register('Maatwebsite\Excel\ExcelServiceProvider'); |
84
|
|
|
$this->app->register('Unisharp\Laravelfilemanager\LaravelFilemanagerServiceProvider'); |
85
|
|
|
$this->app->register('Intervention\Image\ImageServiceProvider'); |
86
|
|
|
$this->app->register('Imanghafoori\Widgets\WidgetsServiceProvider'); |
87
|
|
|
$this->app->register('Imanghafoori\Responder\LaravelResponderServiceProvider'); |
88
|
|
|
|
89
|
|
|
$this->setAliases(); |
90
|
|
|
|
91
|
|
|
$this->app->singleton(\crocodicstudio\crudbooster\CBCoreModule\CbRouter::class); |
92
|
|
|
$this->app->register(CbAuthServiceProvider::class); |
93
|
|
|
$this->app->register(CbApiGeneratorServiceProvider::class); |
94
|
|
|
$this->app->register(CbModulesGeneratorServiceProvider::class); |
95
|
|
|
$this->app->register(CbSettingsServiceProvider::class); |
96
|
|
|
$this->app->register(CbStatisticsServiceProvider::class); |
97
|
|
|
$this->app->register(CbPrivilegesServiceProvider::class); |
98
|
|
|
$this->app->register(CbMenuServiceProvider::class); |
99
|
|
|
$this->app->register(CbFileManagerServiceProvider::class); |
100
|
|
|
$this->app->register(CbNotificationsServiceProvider::class); |
101
|
|
|
$this->app->register(CbEmailTemplatesServiceProvider::class); |
102
|
|
|
$this->app->register(CbLogsServiceProvider::class); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
private function defineValidationRules() |
106
|
|
|
{ |
107
|
|
|
\Validator::extend('alpha_spaces', function ($attribute, $value) { |
108
|
|
|
// This will only accept alpha and spaces. |
109
|
|
|
// If you want to accept hyphens use: /^[\pL\s-]+$/u. |
110
|
|
|
return preg_match('/^[\pL\s]+$/u', $value); |
111
|
|
|
}, 'The :attribute should be letters only'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
private function defineAuthGuard() |
115
|
|
|
{ |
116
|
|
|
config()->offsetSet('auth.providers.cb_users', ['driver' => 'eloquent', 'model' => CbUser::class,]); |
117
|
|
|
config()->offsetSet('auth.guards.cbAdmin', ['driver' => 'session', 'provider' => 'cb_users']); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
private function setAliases(): void |
121
|
|
|
{ |
122
|
|
|
$loader = AliasLoader::getInstance(); |
123
|
|
|
$loader->alias('PDF', 'Barryvdh\DomPDF\Facade'); |
124
|
|
|
$loader->alias('Excel', 'Maatwebsite\Excel\Facades\Excel'); |
125
|
|
|
$loader->alias('Image', 'Intervention\Image\Facades\Image'); |
126
|
|
|
$loader->alias('CRUDBooster', 'crocodicstudio\crudbooster\helpers\CRUDBooster'); |
127
|
|
|
$loader->alias('CB', 'crocodicstudio\crudbooster\helpers\CB'); |
128
|
|
|
$loader->alias('DbInspector', 'crocodicstudio\crudbooster\helpers\DbInspector'); |
129
|
|
|
$loader->alias('CbRouter', CbRouter::class); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|