diff --git a/app/Services/ModuleService.php b/app/Services/ModuleService.php new file mode 100644 index 00000000..705d530b --- /dev/null +++ b/app/Services/ModuleService.php @@ -0,0 +1,69 @@ + [], 1 => []]; + + + /** + * Add a module link in the frontend + * @param string $title + * @param string $url + * @param string $icon + */ + public function addFrontendLink(string $title, string $url, string $icon = '', $logged_in=true) + { + self::$frontendLinks[$logged_in][] = [ + 'title' => $title, + 'url' => $url, + 'icon' => 'pe-7s-users', + ]; + } + + /** + * Get all of the frontend links + * @return array + */ + public function getFrontendLinks($logged_in): array + { + return self::$frontendLinks[$logged_in]; + } + + /** + * Add a module link in the admin panel + * @param string $title + * @param string $url + * @param string $icon + */ + public function addAdminLink(string $title, string $url, string $icon='') + { + self::$adminLinks[] = [ + 'title' => $title, + 'url' => $url, + 'icon' => 'pe-7s-users' + ]; + } + + /** + * Get all of the module links in the admin panel + * @return array + */ + public function getAdminLinks(): array + { + return self::$adminLinks; + } +} diff --git a/modules/Sample/Providers/SampleServiceProvider.php b/modules/Sample/Providers/SampleServiceProvider.php index c4b98cb1..29041089 100644 --- a/modules/Sample/Providers/SampleServiceProvider.php +++ b/modules/Sample/Providers/SampleServiceProvider.php @@ -9,24 +9,23 @@ use Route; class SampleServiceProvider extends ServiceProvider { - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ protected $defer = false; + protected $moduleSvc; /** * Boot the application events. - * - * @return void */ public function boot() { + $this->moduleSvc = app('App\Services\ModuleService'); + $this->registerRoutes(); $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); + + $this->registerLinks(); + $this->registerFactories(); $this->loadMigrationsFrom(__DIR__ . '/../Database/migrations'); } @@ -39,6 +38,18 @@ class SampleServiceProvider extends ServiceProvider // } + /** + * Add module links here + */ + public function registerLinks() + { + // Show this link if logged in + $this->moduleSvc->addFrontendLink('Sample', '/sample', '', $logged_in=true); + + // Admin links: + $this->moduleSvc->addAdminLink('Sample', '/sample/admin'); + } + /** * Register the routes */ diff --git a/resources/modules/stubs/scaffold/provider.stub b/resources/modules/stubs/scaffold/provider.stub index f3fda2c5..f3470a7a 100644 --- a/resources/modules/stubs/scaffold/provider.stub +++ b/resources/modules/stubs/scaffold/provider.stub @@ -9,24 +9,23 @@ use Route; class $CLASS$ extends ServiceProvider { - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ protected $defer = false; + protected $moduleSvc; /** * Boot the application events. - * - * @return void */ 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$'); } @@ -39,6 +38,18 @@ class $CLASS$ extends ServiceProvider // } + /** + * 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: + $this->moduleSvc->addAdminLink('$STUDLY_NAME$', '/$LOWER_NAME$/admin'); + } + /** * Register the routes */ diff --git a/resources/views/admin/menu.blade.php b/resources/views/admin/menu.blade.php index 20db3886..2a17db8c 100644 --- a/resources/views/admin/menu.blade.php +++ b/resources/views/admin/menu.blade.php @@ -46,7 +46,10 @@
diff --git a/resources/views/layouts/default/app.blade.php b/resources/views/layouts/default/app.blade.php index 25c2e72e..909529c1 100644 --- a/resources/views/layouts/default/app.blade.php +++ b/resources/views/layouts/default/app.blade.php @@ -1,3 +1,4 @@ +@inject('moduleSvc', 'App\Services\ModuleService') @@ -58,7 +59,19 @@

Register

+ + {{-- Show the module links for being logged out --}} + @foreach($moduleSvc->getFrontendLinks($logged_in=false) as &$link) + + @endforeach + @else + @endif + + {{-- Show the module links for being logged out --}} + @foreach($moduleSvc->getFrontendLinks($logged_in=true) as &$link) + + @endforeach +