Skip to content

Commit

Permalink
Merge pull request #554 from huydang284/3.0
Browse files Browse the repository at this point in the history
fix route:cache and config:cache issue
  • Loading branch information
nWidart authored Jul 9, 2018
2 parents e22a39d + a86e268 commit 53e8692
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 66 deletions.
7 changes: 7 additions & 0 deletions Modules/Core/Config/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,11 @@
| useViewNamespaces.backend-theme needs to be enabled at module level
*/
'enable-theme-overrides' => false,

/*
|--------------------------------------------------------------------------
| Check if asgard was installed
|--------------------------------------------------------------------------
*/
'is_installed' => env('INSTALLED', false)
];
2 changes: 1 addition & 1 deletion Modules/Core/Providers/CoreServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function boot()
public function register()
{
$this->app->singleton('asgard.isInstalled', function () {
return true === env('INSTALLED', false);
return true === config('asgard.core.core.is_installed');
});
$this->app->singleton('asgard.onBackend', function () {
return $this->onBackend();
Expand Down
32 changes: 24 additions & 8 deletions Modules/Core/Providers/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,30 @@ public function map(Router $router)
$this->loadApiRoutes($router);
});

$router->group([
'namespace' => $this->namespace,
'prefix' => LaravelLocalization::setLocale(),
'middleware' => ['localizationRedirect', 'web'],
], function (Router $router) {
$this->loadBackendRoutes($router);
$this->loadFrontendRoutes($router);
});
$prefixes = $this->getPrefixes();
foreach ($prefixes as $prefix) {
$router->group([
'namespace' => $this->namespace,
'prefix' => $prefix,
'middleware' => ['localizationRedirect', 'web'],
], function (Router $router) {
$this->loadBackendRoutes($router);
$this->loadFrontendRoutes($router);
});
}
}

/**
* Get locale prefixes
* @return array
*/
private function getPrefixes()
{
if (app('asgard.isInstalled')) {
return array_merge(json_decode(setting('core::locales')), ['']);
}

return [LaravelLocalization::setLocale()];
}

/**
Expand Down
4 changes: 0 additions & 4 deletions Modules/Media/Http/backendRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
use Illuminate\Routing\Router;

/** @var Router $router */
$router->bind('media', function ($id) {
return app(\Modules\Media\Repositories\FileRepository::class)->find($id);
});

$router->group(['prefix' => '/media'], function (Router $router) {
$router->get('media', [
'as' => 'admin.media.media.index',
Expand Down
4 changes: 4 additions & 0 deletions Modules/Media/Providers/MediaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public function register()
$event->load('media', array_dot(trans('media::media')));
$event->load('folders', array_dot(trans('media::folders')));
});

app('router')->bind('media', function ($id) {
return app(FileRepository::class)->find($id);
});
}

public function boot(DispatcherContract $events)
Expand Down
7 changes: 0 additions & 7 deletions Modules/Menu/Http/backendRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
use Illuminate\Routing\Router;

/** @var Router $router */
$router->bind('menu', function ($id) {
return app(\Modules\Menu\Repositories\MenuRepository::class)->find($id);
});
$router->bind('menuitem', function ($id) {
return app(\Modules\Menu\Repositories\MenuItemRepository::class)->find($id);
});

$router->group(['prefix' => '/menu'], function (Router $router) {
$router->get('menus', [
'as' => 'admin.menu.menu.index',
Expand Down
7 changes: 7 additions & 0 deletions Modules/Menu/Providers/MenuServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public function register()
$event->load('menu', array_dot(trans('menu::menu')));
$event->load('menu-items', array_dot(trans('menu::menu-items')));
});

app('router')->bind('menu', function ($id) {
return app(MenuRepository::class)->find($id);
});
app('router')->bind('menuitem', function ($id) {
return app(MenuItemRepository::class)->find($id);
});
}

/**
Expand Down
4 changes: 0 additions & 4 deletions Modules/Page/Http/apiRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
use Illuminate\Routing\Router;

/** @var Router $router */
$router->bind('page', function ($id) {
return app(\Modules\Page\Repositories\PageRepository::class)->find($id);
});

$router->group(['prefix' => '/page', 'middleware' => ['api.token', 'auth.admin']], function (Router $router) {
$router->get('pages', [
'as' => 'api.page.page.index',
Expand Down
4 changes: 0 additions & 4 deletions Modules/Page/Http/backendRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
use Illuminate\Routing\Router;

/** @var Router $router */
$router->bind('page', function ($id) {
return app(\Modules\Page\Repositories\PageRepository::class)->find($id);
});

$router->group(['prefix' => '/page'], function (Router $router) {
$router->get('pages', [
'as' => 'admin.page.page.index',
Expand Down
22 changes: 10 additions & 12 deletions Modules/Page/Http/frontendRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
use Illuminate\Routing\Router;

/** @var Router $router */
if (! App::runningInConsole()) {
$router->get('/', [
'uses' => 'PublicController@homepage',
'as' => 'homepage',
'middleware' => config('asgard.page.config.middleware'),
]);
$router->any('{uri}', [
'uses' => 'PublicController@uri',
'as' => 'page',
'middleware' => config('asgard.page.config.middleware'),
])->where('uri', '.*');
}
$router->get('/', [
'uses' => 'PublicController@homepage',
'as' => 'homepage',
'middleware' => config('asgard.page.config.middleware'),
]);
$router->any('{uri}', [
'uses' => 'PublicController@uri',
'as' => 'page',
'middleware' => config('asgard.page.config.middleware'),
])->where('uri', '.*');
4 changes: 4 additions & 0 deletions Modules/Page/Providers/PageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public function register()
$this->app['events']->listen(LoadingBackendTranslations::class, function (LoadingBackendTranslations $event) {
$event->load('pages', array_dot(trans('page::pages')));
});

app('router')->bind('page', function ($id) {
return app(PageRepository::class)->find($id);
});
}

public function boot()
Expand Down
3 changes: 0 additions & 3 deletions Modules/Tag/Http/backendRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

/** @var Router $router */
$router->group(['prefix' => 'tag'], function (Router $router) {
$router->bind('tag__tag', function ($id) {
return app(\Modules\Tag\Repositories\TagRepository::class)->find($id);
});
$router->get('tags', [
'as' => 'admin.tag.tag.index',
'uses' => 'TagController@index',
Expand Down
4 changes: 4 additions & 0 deletions Modules/Tag/Providers/TagServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function register()
$this->app['events']->listen(LoadingBackendTranslations::class, function (LoadingBackendTranslations $event) {
$event->load('tags', array_dot(trans('tag::tags')));
});

app('router')->bind('tag__tag', function ($id) {
return app(TagRepository::class)->find($id);
});
}

public function boot()
Expand Down
3 changes: 0 additions & 3 deletions Modules/Translation/Http/backendRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

/** @var Router $router */
$router->group(['prefix' =>'/translation'], function (Router $router) {
$router->bind('translations', function ($id) {
return \Modules\Translation\Entities\TranslationTranslation::find($id);
});
$router->get('translations', [
'uses' => 'TranslationController@index',
'as' => 'admin.translation.translation.index',
Expand Down
5 changes: 5 additions & 0 deletions Modules/Translation/Providers/TranslationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Translation\Console\BuildTranslationsCacheCommand;
use Modules\Translation\Entities\Translation;
use Modules\Translation\Entities\TranslationTranslation;
use Modules\Translation\Events\Handlers\RegisterTranslationSidebar;
use Modules\Translation\Repositories\Cache\CacheTranslationDecorator;
use Modules\Translation\Repositories\Eloquent\EloquentTranslationRepository;
Expand Down Expand Up @@ -50,6 +51,10 @@ public function register()
$this->app['events']->listen(LoadingBackendTranslations::class, function (LoadingBackendTranslations $event) {
$event->load('translations', array_dot(trans('translation::translations')));
});

app('router')->bind('translations', function ($id) {
return TranslationTranslation::find($id);
});
}

public function boot()
Expand Down
10 changes: 0 additions & 10 deletions Modules/User/Http/apiRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
/** @var Router $router */
$router->group(['prefix' => '/user', 'middleware' => ['api.token', 'auth.admin']], function (Router $router) {
$router->group(['prefix' => 'roles'], function (Router $router) {
$router->bind('role', function ($id) {
return app(\Modules\User\Repositories\RoleRepository::class)->find($id);
});
$router->get('/', [
'as' => 'api.user.role.index',
'uses' => 'RoleController@index',
Expand Down Expand Up @@ -46,9 +43,6 @@
});

$router->group(['prefix' => 'users'], function (Router $router) {
$router->bind('user', function ($id) {
return app(\Modules\User\Repositories\UserRepository::class)->find($id);
});
$router->get('/', [
'as' => 'api.user.user.index',
'uses' => 'UserController@index',
Expand Down Expand Up @@ -96,10 +90,6 @@
'uses' => 'ProfileController@update',
]);

$router->bind('userTokenId', function ($id) {
return app(\Modules\User\Repositories\UserTokenRepository::class)->find($id);
});

$router->get('api-keys', [
'as' => 'api.account.api.index',
'uses' => 'ApiKeysController@index',
Expand Down
3 changes: 0 additions & 3 deletions Modules/User/Http/backendRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@
'as' => 'admin.account.profile.update',
'uses' => 'Account\ProfileController@update',
]);
$router->bind('userTokenId', function ($id) {
return app(\Modules\User\Repositories\UserTokenRepository::class)->find($id);
});
$router->get('api-keys', [
'as' => 'admin.account.api.index',
'uses' => 'Account\ApiKeysController@index',
Expand Down
10 changes: 10 additions & 0 deletions Modules/User/Providers/UserServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public function register()
GrantModulePermissionsCommand::class,
RemoveModulePermissionsCommand::class,
]);

app('router')->bind('role', function ($id) {
return app(RoleRepository::class)->find($id);
});
app('router')->bind('user', function ($id) {
return app(UserRepository::class)->find($id);
});
app('router')->bind('userTokenId', function ($id) {
return app(UserTokenRepository::class)->find($id);
});
}

/**
Expand Down
7 changes: 0 additions & 7 deletions Modules/Workshop/Http/backendRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
use Illuminate\Routing\Router;

/** @var Router $router */
$router->bind('module', function ($module) {
return app(\Nwidart\Modules\Contracts\RepositoryInterface::class)->find($module);
});
$router->bind('theme', function ($theme) {
return app(\Modules\Workshop\Manager\ThemeManager::class)->find($theme);
});

$router->group(
['prefix' => '/workshop'],
function (Router $router) {
Expand Down
8 changes: 8 additions & 0 deletions Modules/Workshop/Providers/WorkshopServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Modules\Workshop\Scaffold\Module\ModuleScaffold;
use Modules\Workshop\Scaffold\Theme\ThemeGeneratorFactory;
use Modules\Workshop\Scaffold\Theme\ThemeScaffold;
use Nwidart\Modules\Repository;

class WorkshopServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -52,6 +53,13 @@ public function register()
$event->load('modules', array_dot(trans('workshop::modules')));
$event->load('themes', array_dot(trans('workshop::themes')));
});

app('router')->bind('module', function ($module) {
return app(Repository::class)->find($module);
});
app('router')->bind('theme', function ($theme) {
return app(ThemeManager::class)->find($theme);
});
}

public function boot()
Expand Down
7 changes: 7 additions & 0 deletions config/asgard/core/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,11 @@
| useViewNamespaces.backend-theme needs to be enabled at module level
*/
'enable-theme-overrides' => false,

/*
|--------------------------------------------------------------------------
| Check if asgard was installed
|--------------------------------------------------------------------------
*/
'is_installed' => env('INSTALLED', false)
];

0 comments on commit 53e8692

Please sign in to comment.