2017-12-14 12:24:41 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace $NAMESPACE$;
|
|
|
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
use Illuminate\Database\Eloquent\Factory;
|
|
|
|
use Route;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class $CLASS$
|
|
|
|
* @package $NAMESPACE$
|
|
|
|
*/
|
2017-12-14 12:24:41 +08:00
|
|
|
class $CLASS$ extends ServiceProvider
|
|
|
|
{
|
2018-03-20 09:50:40 +08:00
|
|
|
private $moduleSvc;
|
|
|
|
|
2017-12-14 12:24:41 +08:00
|
|
|
protected $defer = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Boot the application events.
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
|
|
|
$this->moduleSvc = app('App\Services\ModuleService');
|
|
|
|
|
|
|
|
$this->registerRoutes();
|
|
|
|
$this->registerTranslations();
|
|
|
|
$this->registerConfig();
|
|
|
|
$this->registerViews();
|
|
|
|
|
|
|
|
$this->registerLinks();
|
|
|
|
|
|
|
|
$this->registerFactories();
|
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/../$MIGRATIONS_PATH$');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the service provider.
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add module links here
|
|
|
|
*/
|
|
|
|
public function registerLinks()
|
|
|
|
{
|
|
|
|
// Show this link if logged in
|
|
|
|
// $this->moduleSvc->addFrontendLink('$STUDLY_NAME$', '/$LOWER_NAME$', '', $logged_in=true);
|
|
|
|
|
|
|
|
// Admin links:
|
2018-03-01 05:16:36 +08:00
|
|
|
$this->moduleSvc->addAdminLink('$STUDLY_NAME$', '/admin/$LOWER_NAME$');
|
2017-12-14 12:24:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the routes
|
|
|
|
*/
|
|
|
|
protected function registerRoutes()
|
|
|
|
{
|
2018-02-09 09:09:36 +08:00
|
|
|
/**
|
|
|
|
* Routes for the frontend
|
|
|
|
*/
|
2017-12-14 12:24:41 +08:00
|
|
|
Route::group([
|
|
|
|
'as' => '$LOWER_NAME$.',
|
|
|
|
'prefix' => '$LOWER_NAME$',
|
|
|
|
// If you want a RESTful module, change this to 'api'
|
|
|
|
'middleware' => ['web'],
|
|
|
|
'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'
|
|
|
|
], function() {
|
2018-02-09 09:09:36 +08:00
|
|
|
$this->loadRoutesFrom(__DIR__ . '/../Http/Routes/web.php');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Routes for the admin
|
|
|
|
*/
|
|
|
|
Route::group([
|
|
|
|
'as' => '$LOWER_NAME$.',
|
2018-03-01 05:16:36 +08:00
|
|
|
'prefix' => 'admin/$LOWER_NAME$',
|
2018-02-09 09:09:36 +08:00
|
|
|
// If you want a RESTful module, change this to 'api'
|
|
|
|
'middleware' => ['web', 'role:admin'],
|
|
|
|
'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers\Admin'
|
|
|
|
], function() {
|
|
|
|
$this->loadRoutesFrom(__DIR__ . '/../Http/Routes/admin.php');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Routes for an API
|
|
|
|
*/
|
|
|
|
Route::group([
|
|
|
|
'as' => '$LOWER_NAME$.',
|
|
|
|
'prefix' => 'api/$LOWER_NAME$',
|
|
|
|
// If you want a RESTful module, change this to 'api'
|
|
|
|
'middleware' => ['api'],
|
|
|
|
'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers\Api'
|
|
|
|
], function() {
|
|
|
|
$this->loadRoutesFrom(__DIR__ . '/../Http/Routes/api.php');
|
2017-12-14 12:24:41 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register config.
|
|
|
|
*/
|
|
|
|
protected function registerConfig()
|
|
|
|
{
|
|
|
|
$this->publishes([
|
|
|
|
__DIR__.'/../$PATH_CONFIG$/config.php' => config_path('$LOWER_NAME$.php'),
|
2018-02-26 01:12:01 +08:00
|
|
|
], '$LOWER_NAME$');
|
2017-12-14 12:24:41 +08:00
|
|
|
|
|
|
|
$this->mergeConfigFrom(
|
|
|
|
__DIR__.'/../$PATH_CONFIG$/config.php', '$LOWER_NAME$'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register views.
|
|
|
|
*/
|
|
|
|
public function registerViews()
|
|
|
|
{
|
|
|
|
$viewPath = resource_path('views/modules/$LOWER_NAME$');
|
|
|
|
$sourcePath = __DIR__.'/../$PATH_VIEWS$';
|
|
|
|
|
|
|
|
$this->publishes([
|
|
|
|
$sourcePath => $viewPath
|
|
|
|
],'views');
|
|
|
|
|
|
|
|
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
|
|
|
return $path . '/modules/$LOWER_NAME$';
|
|
|
|
}, \Config::get('view.paths')), [$sourcePath]), '$LOWER_NAME$');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register translations.
|
|
|
|
*/
|
|
|
|
public function registerTranslations()
|
|
|
|
{
|
|
|
|
$langPath = resource_path('lang/modules/$LOWER_NAME$');
|
|
|
|
|
|
|
|
if (is_dir($langPath)) {
|
|
|
|
$this->loadTranslationsFrom($langPath, '$LOWER_NAME$');
|
|
|
|
} else {
|
|
|
|
$this->loadTranslationsFrom(__DIR__ .'/../$PATH_LANG$', '$LOWER_NAME$');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register an additional directory of factories.
|
|
|
|
* @source https://github.com/sebastiaanluca/laravel-resource-flow/blob/develop/src/Modules/ModuleServiceProvider.php#L66
|
|
|
|
*/
|
|
|
|
public function registerFactories()
|
|
|
|
{
|
|
|
|
if (! app()->environment('production')) {
|
|
|
|
app(Factory::class)->load(__DIR__ . '/../$FACTORIES_PATH$');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the services provided by the provider.
|
|
|
|
*/
|
|
|
|
public function provides()
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|