From 21c7fa4dc6fceb2812896ed6f0dbdf02ebc94aca Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 1 Dec 2017 14:38:30 -0600 Subject: [PATCH] Sample module --- .gitignore | 1 + modules/.gitignore | 2 +- modules/Sample/Config/config.php | 5 + .../Database/seeders/SampleDatabaseSeeder.php | 21 ++++ .../Http/Controllers/AdminController.php | 63 ++++++++++ .../Http/Controllers/SampleController.php | 64 ++++++++++ modules/Sample/Http/routes.php | 24 ++++ .../Providers/SampleServiceProvider.php | 111 ++++++++++++++++++ .../Resources/views/admin/index.blade.php | 18 +++ .../Sample/Resources/views/index.blade.php | 9 ++ .../Resources/views/layouts/admin.blade.php | 5 + .../views/layouts/frontend.blade.php | 5 + modules/Sample/composer.json | 25 ++++ modules/Sample/module.json | 16 +++ modules/Sample/start.php | 17 +++ 15 files changed, 385 insertions(+), 1 deletion(-) create mode 100644 modules/Sample/Config/config.php create mode 100644 modules/Sample/Database/seeders/SampleDatabaseSeeder.php create mode 100644 modules/Sample/Http/Controllers/AdminController.php create mode 100644 modules/Sample/Http/Controllers/SampleController.php create mode 100644 modules/Sample/Http/routes.php create mode 100644 modules/Sample/Providers/SampleServiceProvider.php create mode 100644 modules/Sample/Resources/views/admin/index.blade.php create mode 100644 modules/Sample/Resources/views/index.blade.php create mode 100644 modules/Sample/Resources/views/layouts/admin.blade.php create mode 100644 modules/Sample/Resources/views/layouts/frontend.blade.php create mode 100644 modules/Sample/composer.json create mode 100644 modules/Sample/module.json create mode 100644 modules/Sample/start.php diff --git a/.gitignore b/.gitignore index 35a7317c..542992c8 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,4 @@ error_log .sass-cache .DS_Store +Sample/ diff --git a/modules/.gitignore b/modules/.gitignore index fe6395ae..2bd91a68 100644 --- a/modules/.gitignore +++ b/modules/.gitignore @@ -3,4 +3,4 @@ # But keep the sample and this file around !.gitignore -!Sample +!Sample/** diff --git a/modules/Sample/Config/config.php b/modules/Sample/Config/config.php new file mode 100644 index 00000000..36578109 --- /dev/null +++ b/modules/Sample/Config/config.php @@ -0,0 +1,5 @@ + 'Sample' +]; diff --git a/modules/Sample/Database/seeders/SampleDatabaseSeeder.php b/modules/Sample/Database/seeders/SampleDatabaseSeeder.php new file mode 100644 index 00000000..dad32f12 --- /dev/null +++ b/modules/Sample/Database/seeders/SampleDatabaseSeeder.php @@ -0,0 +1,21 @@ +call("OthersTableSeeder"); + } +} diff --git a/modules/Sample/Http/Controllers/AdminController.php b/modules/Sample/Http/Controllers/AdminController.php new file mode 100644 index 00000000..596724f3 --- /dev/null +++ b/modules/Sample/Http/Controllers/AdminController.php @@ -0,0 +1,63 @@ + 'sample.', + 'prefix' => 'sample', + 'middleware' => [ + 'web', + 'role:admin|user' # leave blank for public + ], + 'namespace' => 'Modules\Sample\Http\Controllers' +], function() { + + # all your routes are prefixed with the above prefix + # e.g. yoursite.com/sample + Route::get('/', 'SampleController@index'); + + # This is the admin path. Comment this out if you don't have + # an admin panel component. + Route::group([ + 'middleware' => ['role:admin'], + ], function () { + Route::get('/admin', 'AdminController@index'); + }); +}); diff --git a/modules/Sample/Providers/SampleServiceProvider.php b/modules/Sample/Providers/SampleServiceProvider.php new file mode 100644 index 00000000..2836dfa1 --- /dev/null +++ b/modules/Sample/Providers/SampleServiceProvider.php @@ -0,0 +1,111 @@ +registerRoutes(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->registerFactories(); + $this->loadMigrationsFrom(__DIR__ . '/../Database/migrations'); + } + + /** + * Register the service provider. + */ + public function register() + { + // + } + + /** + * Register the routes + */ + protected function registerRoutes() + { + $this->loadRoutesFrom(__DIR__ . '/../Http/routes.php'); + } + + /** + * Register config. + */ + protected function registerConfig() + { + $this->publishes([ + __DIR__.'/../Config/config.php' => config_path('sample.php'), + ], 'config'); + + $this->mergeConfigFrom( + __DIR__.'/../Config/config.php', 'sample' + ); + } + + /** + * Register views. + */ + public function registerViews() + { + $viewPath = resource_path('views/modules/sample'); + $sourcePath = __DIR__.'/../Resources/views'; + + $this->publishes([ + $sourcePath => $viewPath + ],'views'); + + $this->loadViewsFrom(array_merge(array_map(function ($path) { + return $path . '/modules/sample'; + }, \Config::get('view.paths')), [$sourcePath]), 'sample'); + } + + /** + * Register translations. + */ + public function registerTranslations() + { + $langPath = resource_path('lang/modules/sample'); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, 'sample'); + } else { + $this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'sample'); + } + } + + /** + * 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__ . '/../Database/factories'); + } + } + + /** + * Get the services provided by the provider. + */ + public function provides() + { + return []; + } +} diff --git a/modules/Sample/Resources/views/admin/index.blade.php b/modules/Sample/Resources/views/admin/index.blade.php new file mode 100644 index 00000000..62e588c0 --- /dev/null +++ b/modules/Sample/Resources/views/admin/index.blade.php @@ -0,0 +1,18 @@ +@extends('sample::layouts.admin') + +@section('title', 'Sample') +@section('actions') +
  • + + + Add New +
  • +@endsection +@section('content') +
    +

    Admin Scaffold!

    +
    +

    This view is loaded from module: {!! config('sample.name') !!}

    +
    +
    +@endsection diff --git a/modules/Sample/Resources/views/index.blade.php b/modules/Sample/Resources/views/index.blade.php new file mode 100644 index 00000000..6198e2fb --- /dev/null +++ b/modules/Sample/Resources/views/index.blade.php @@ -0,0 +1,9 @@ +@extends('sample::layouts.frontend') + +@section('content') +

    Hello World

    + +

    + This view is loaded from module: {!! config('sample.name') !!} +

    +@endsection diff --git a/modules/Sample/Resources/views/layouts/admin.blade.php b/modules/Sample/Resources/views/layouts/admin.blade.php new file mode 100644 index 00000000..421bbe11 --- /dev/null +++ b/modules/Sample/Resources/views/layouts/admin.blade.php @@ -0,0 +1,5 @@ +{{-- +You probably don't want to edit anything here. Just make +sure to extend this in your views. It will pass the content section through +--}} +@extends('admin.app') diff --git a/modules/Sample/Resources/views/layouts/frontend.blade.php b/modules/Sample/Resources/views/layouts/frontend.blade.php new file mode 100644 index 00000000..9340e4f9 --- /dev/null +++ b/modules/Sample/Resources/views/layouts/frontend.blade.php @@ -0,0 +1,5 @@ +{{-- +You probably don't want to edit anything here. Just make +sure to extend this in your views. It will pass the content section through +--}} +@extends('layouts.' . config('phpvms.skin') . '.app') diff --git a/modules/Sample/composer.json b/modules/Sample/composer.json new file mode 100644 index 00000000..90256c27 --- /dev/null +++ b/modules/Sample/composer.json @@ -0,0 +1,25 @@ +{ + "name": "/sample", + "description": "", + "authors": [ + { + "name": "", + "email": "" + } + ], + "extra": { + "laravel": { + "providers": [ + "Modules\\Sample\\Providers\\SampleServiceProvider" + ], + "aliases": { + + } + } + }, + "autoload": { + "psr-4": { + "Modules\\Sample\\": "" + } + } +} diff --git a/modules/Sample/module.json b/modules/Sample/module.json new file mode 100644 index 00000000..4f60e44c --- /dev/null +++ b/modules/Sample/module.json @@ -0,0 +1,16 @@ +{ + "name": "Sample", + "alias": "sample", + "description": "", + "keywords": [], + "active": 1, + "order": 0, + "providers": [ + "Modules\\Sample\\Providers\\SampleServiceProvider" + ], + "aliases": {}, + "files": [ + "start.php" + ], + "requires": [] +} diff --git a/modules/Sample/start.php b/modules/Sample/start.php new file mode 100644 index 00000000..f062bff0 --- /dev/null +++ b/modules/Sample/start.php @@ -0,0 +1,17 @@ +routesAreCached()) { + require __DIR__ . '/Http/routes.php'; +}*/