diff --git a/Modules/Leave/app/Http/Controllers/.gitkeep b/Modules/Leave/app/Http/Controllers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Leave/app/Http/Controllers/LeaveController.php b/Modules/Leave/app/Http/Controllers/LeaveController.php new file mode 100644 index 0000000..7f65e29 --- /dev/null +++ b/Modules/Leave/app/Http/Controllers/LeaveController.php @@ -0,0 +1,84 @@ +leaveRepository = $leaveRepository; + } + + /** + * Display a listing of the resource. + */ + public function index() + { + $data['leaves'] = $this->leaveRepository->findAll(); + // dd($data['leaves']); + return view('leave::index'); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + $data['title'] = 'Create Leave'; + return view('leave::create', $data); + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request): RedirectResponse + { + $inputData = $request->all(); + try { + $this->leaveRepository->create($inputData); + toastr()->success('Leave Created Succesfully'); + } catch (\Throwable $th) { + toastr()->error($th->getMessage()); + } + return redirect()->route('leave.index'); + } + + /** + * Show the specified resource. + */ + public function show($id) + { + return view('leave::show'); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit($id) + { + return view('leave::edit'); + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, $id): RedirectResponse + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy($id) + { + // + } +} diff --git a/Modules/Leave/app/Http/Requests/.gitkeep b/Modules/Leave/app/Http/Requests/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Leave/app/Models/.gitkeep b/Modules/Leave/app/Models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Leave/app/Models/Leave.php b/Modules/Leave/app/Models/Leave.php new file mode 100644 index 0000000..48f2185 --- /dev/null +++ b/Modules/Leave/app/Models/Leave.php @@ -0,0 +1,12 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->bind(LeaveInterface::class, LeaveRepository::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = str_replace('/', '\\', config('modules.namespace').'\\'.$this->moduleName.'\\'.ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder',''))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + */ + public function provides(): array + { + return []; + } + + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/Modules/Leave/app/Providers/RouteServiceProvider.php b/Modules/Leave/app/Providers/RouteServiceProvider.php new file mode 100644 index 0000000..29b900e --- /dev/null +++ b/Modules/Leave/app/Providers/RouteServiceProvider.php @@ -0,0 +1,49 @@ +mapApiRoutes(); + + $this->mapWebRoutes(); + } + + /** + * Define the "web" routes for the application. + * + * These routes all receive session state, CSRF protection, etc. + */ + protected function mapWebRoutes(): void + { + Route::middleware('web')->group(module_path('Leave', '/routes/web.php')); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + */ + protected function mapApiRoutes(): void + { + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Leave', '/routes/api.php')); + } +} diff --git a/Modules/Leave/app/Repositories/.gitkeep b/Modules/Leave/app/Repositories/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Modules/Leave/app/Repositories/LeaveInterface.php b/Modules/Leave/app/Repositories/LeaveInterface.php new file mode 100644 index 0000000..d34795e --- /dev/null +++ b/Modules/Leave/app/Repositories/LeaveInterface.php @@ -0,0 +1,12 @@ +update($newDetails); + } + +} diff --git a/Modules/Leave/database/factories/.gitkeep b/Modules/Leave/database/factories/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/composer.json b/composer.json index 1915f0d..12ecf9e 100644 --- a/composer.json +++ b/composer.json @@ -29,8 +29,7 @@ "psr-4": { "App\\": "app/", "Database\\Factories\\": "database/factories/", - "Database\\Seeders\\": "database/seeders/", - "Modules\\": "Modules/" + "Database\\Seeders\\": "database/seeders/" }, "files":[ "app/Helpers/OMIS.php", @@ -64,6 +63,11 @@ }, "laravel": { "dont-discover": [] + }, + "merge-plugin": { + "include": [ + "Modules/*/composer.json" + ] } }, "config": { diff --git a/composer.lock b/composer.lock index c0ca3ed..a23a23e 100644 --- a/composer.lock +++ b/composer.lock @@ -8865,5 +8865,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/config/modules.php b/config/modules.php index e65458e..fa95874 100644 --- a/config/modules.php +++ b/config/modules.php @@ -12,7 +12,7 @@ return [ | | Default module namespace. | - */ + */ 'namespace' => 'Modules', @@ -23,7 +23,7 @@ return [ | | Default module stubs. | - */ + */ 'stubs' => [ 'enabled' => false, @@ -69,7 +69,7 @@ return [ | This path is used to save the generated module. | This path will also be added automatically to the list of scanned folders. | - */ + */ 'modules' => base_path('Modules'), /* @@ -79,7 +79,7 @@ return [ | | Here you may update the modules' assets path. | - */ + */ 'assets' => public_path('modules'), /* @@ -90,7 +90,7 @@ return [ | Where you run the 'module:publish-migration' command, where do you publish the | the migration files? | - */ + */ 'migration' => base_path('database/migrations'), @@ -101,8 +101,8 @@ return [ | | app folder name | for example can change it to 'src' or 'App' - */ - 'app_folder' => '', + */ + 'app_folder' => 'app/', /* |-------------------------------------------------------------------------- @@ -110,30 +110,30 @@ return [ |-------------------------------------------------------------------------- | Customise the paths where the folders will be generated. | Setting the generate key to false will not generate that folder - */ + */ 'generator' => [ - // - 'channels' => ['path' => 'Broadcasting', 'generate' => false], - 'command' => ['path' => 'Console', 'generate' => false], - 'emails' => ['path' => 'Emails', 'generate' => false], - 'event' => ['path' => 'Events', 'generate' => false], - 'jobs' => ['path' => 'Jobs', 'generate' => false], - 'listener' => ['path' => 'Listeners', 'generate' => false], - 'model' => ['path' => 'Models', 'generate' => true], - 'notifications' => ['path' => 'Notifications', 'generate' => false], - 'observer' => ['path' => 'Observers', 'generate' => false], - 'policies' => ['path' => 'Policies', 'generate' => false], - 'provider' => ['path' => 'Providers', 'generate' => true], - 'route-provider' => ['path' => 'Providers', 'generate' => true], - 'repository' => ['path' => 'Repositories', 'generate' => true], - 'resource' => ['path' => 'Transformers', 'generate' => false], - 'rules' => ['path' => 'Rules', 'generate' => false], - 'component-class' => ['path' => 'View/Components', 'generate' => false], + // app/ + 'channels' => ['path' => 'app/Broadcasting', 'generate' => false], + 'command' => ['path' => 'app/Console', 'generate' => false], + 'emails' => ['path' => 'app/Emails', 'generate' => false], + 'event' => ['path' => 'app/Events', 'generate' => false], + 'jobs' => ['path' => 'app/Jobs', 'generate' => false], + 'listener' => ['path' => 'app/Listeners', 'generate' => false], + 'model' => ['path' => 'app/Models', 'generate' => true], + 'notifications' => ['path' => 'app/Notifications', 'generate' => false], + 'observer' => ['path' => 'app/Observers', 'generate' => false], + 'policies' => ['path' => 'app/Policies', 'generate' => false], + 'provider' => ['path' => 'app/Providers', 'generate' => true], + 'route-provider' => ['path' => 'app/Providers', 'generate' => true], + 'repository' => ['path' => 'app/Repositories', 'generate' => true], + 'resource' => ['path' => 'app/Transformers', 'generate' => false], + 'rules' => ['path' => 'app/Rules', 'generate' => false], + 'component-class' => ['path' => 'app/View/Components', 'generate' => false], - // Http/ - 'controller' => ['path' => 'Http/Controllers', 'generate' => true], - 'filter' => ['path' => 'Http/Middleware', 'generate' => false], - 'request' => ['path' => 'Http/Requests', 'generate' => false], + // app/Http/ + 'controller' => ['path' => 'app/Http/Controllers', 'generate' => true], + 'filter' => ['path' => 'app/Http/Middleware', 'generate' => false], + 'request' => ['path' => 'app/Http/Requests', 'generate' => true], // config/ 'config' => ['path' => 'config', 'generate' => true], @@ -141,7 +141,7 @@ return [ // database/ 'migration' => ['path' => 'database/migrations', 'generate' => true], 'seeder' => ['path' => 'database/seeders', 'generate' => true], - 'factory' => ['path' => 'database/factories', 'generate' => false], + 'factory' => ['path' => 'database/factories', 'generate' => true], // lang/ 'lang' => ['path' => 'lang', 'generate' => false], @@ -168,7 +168,7 @@ return [ | Here you can define which commands will be visible and used in your | application. You can add your own commands to merge section. | - */ + */ 'commands' => ConsoleServiceProvider::defaultCommands() ->merge([ // New commands go here @@ -182,7 +182,7 @@ return [ | Here you define which folder will be scanned. By default will scan vendor | directory. This is useful if you host the package in packagist website. | - */ + */ 'scan' => [ 'enabled' => false, @@ -197,7 +197,7 @@ return [ | | Here is the config for the composer.json file, generated by this package | - */ + */ 'composer' => [ 'vendor' => env('MODULES_VENDOR', 'nwidart'), @@ -215,7 +215,7 @@ return [ | | Here is the config for setting up the caching feature. | - */ + */ 'cache' => [ 'enabled' => false, 'driver' => 'file', @@ -228,7 +228,7 @@ return [ | Setting one to false will require you to register that part | in your own Service Provider class. |-------------------------------------------------------------------------- - */ + */ 'register' => [ 'translations' => true, /** @@ -245,7 +245,7 @@ return [ | You can define new types of activators here, file, database, etc. The only | required parameter is 'class'. | The file activator will store the activation status in storage/installed_modules - */ + */ 'activators' => [ 'file' => [ 'class' => FileActivator::class, diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 0272877..03b0033 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; // use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\Hash; use Spatie\Permission\Models\Permission; use Spatie\Permission\Models\Role; @@ -19,11 +20,15 @@ class DatabaseSeeder extends Seeder $admin = \App\Models\User::factory()->create([ 'name' => 'Admin User', 'email' => 'admin@gmail.com', + 'password' => Hash::make('password'), + ]); $member = \App\Models\User::factory()->create([ 'name' => 'Member User', 'email' => 'member@gmail.com', + 'password' => Hash::make('password'), + ]); $adminRole = Role::create(['name' => 'admin']); diff --git a/resources/views/layouts/partials/sidebar.blade.php b/resources/views/layouts/partials/sidebar.blade.php index bda2609..f557031 100644 --- a/resources/views/layouts/partials/sidebar.blade.php +++ b/resources/views/layouts/partials/sidebar.blade.php @@ -65,7 +65,7 @@