Merge branch 'main' of ssh://bibgit.com:22022/dharmaraj/New-OMIS

This commit is contained in:
Ranjan 2024-04-05 10:03:38 +05:45
commit 6717db6f4a
17 changed files with 358 additions and 40 deletions

View File

@ -0,0 +1,84 @@
<?php
namespace Modules\Leave\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Leave\Repositories\LeaveInterface;
class LeaveController extends Controller
{
private LeaveInterface $leaveRepository;
public function __construct(LeaveInterface $leaveRepository)
{
$this->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)
{
//
}
}

View File

View File

View File

@ -0,0 +1,12 @@
<?php
namespace Modules\Leave\Models;
use Illuminate\Database\Eloquent\Model;
class Leave extends Model
{
protected $table = 'leaves';
protected $guarded = [];
}

View File

View File

@ -0,0 +1,118 @@
<?php
namespace Modules\Leave\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\Leave\Repositories\LeaveInterface;
use Modules\Leave\Repositories\LeaveRepository;
class LeaveServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Leave';
protected string $moduleNameLower = 'leave';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->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;
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace Modules\Leave\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*/
public function boot(): void
{
parent::boot();
}
/**
* Define the routes for the application.
*/
public function map(): void
{
$this->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'));
}
}

View File

View File

@ -0,0 +1,12 @@
<?php
namespace Modules\Leave\Repositories;
interface LeaveInterface
{
public function findAll();
public function getLeaveById($leaveId);
public function delete($leaveId);
public function create(array $LeaveDetails);
public function update($leaveId, array $newDetails);
}

View File

@ -0,0 +1,34 @@
<?php
namespace Modules\Leave\Repositories;
use Modules\Leave\Models\Leave;
class LeaveRepository implements LeaveInterface
{
public function findAll()
{
return Leave::get();
}
public function getLeaveById($leaveId)
{
return Leave::findOrFail($leaveId);
}
public function delete($leaveId)
{
Leave::destroy($leaveId);
}
public function create(array $leaveDetails)
{
return Leave::create($leaveDetails);
}
public function update($leaveId, array $newDetails)
{
return Leave::whereId($leaveId)->update($newDetails);
}
}

View File

@ -29,8 +29,7 @@
"psr-4": { "psr-4": {
"App\\": "app/", "App\\": "app/",
"Database\\Factories\\": "database/factories/", "Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/", "Database\\Seeders\\": "database/seeders/"
"Modules\\": "Modules/"
}, },
"files":[ "files":[
"app/Helpers/OMIS.php", "app/Helpers/OMIS.php",
@ -64,6 +63,11 @@
}, },
"laravel": { "laravel": {
"dont-discover": [] "dont-discover": []
},
"merge-plugin": {
"include": [
"Modules/*/composer.json"
]
} }
}, },
"config": { "config": {

2
composer.lock generated
View File

@ -8865,5 +8865,5 @@
"php": "^8.1" "php": "^8.1"
}, },
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.6.0" "plugin-api-version": "2.3.0"
} }

View File

@ -102,7 +102,7 @@ return [
| app folder name | app folder name
| for example can change it to 'src' or 'App' | for example can change it to 'src' or 'App'
*/ */
'app_folder' => '', 'app_folder' => 'app/',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -112,28 +112,28 @@ return [
| Setting the generate key to false will not generate that folder | Setting the generate key to false will not generate that folder
*/ */
'generator' => [ 'generator' => [
// // app/
'channels' => ['path' => 'Broadcasting', 'generate' => false], 'channels' => ['path' => 'app/Broadcasting', 'generate' => false],
'command' => ['path' => 'Console', 'generate' => false], 'command' => ['path' => 'app/Console', 'generate' => false],
'emails' => ['path' => 'Emails', 'generate' => false], 'emails' => ['path' => 'app/Emails', 'generate' => false],
'event' => ['path' => 'Events', 'generate' => false], 'event' => ['path' => 'app/Events', 'generate' => false],
'jobs' => ['path' => 'Jobs', 'generate' => false], 'jobs' => ['path' => 'app/Jobs', 'generate' => false],
'listener' => ['path' => 'Listeners', 'generate' => false], 'listener' => ['path' => 'app/Listeners', 'generate' => false],
'model' => ['path' => 'Models', 'generate' => true], 'model' => ['path' => 'app/Models', 'generate' => true],
'notifications' => ['path' => 'Notifications', 'generate' => false], 'notifications' => ['path' => 'app/Notifications', 'generate' => false],
'observer' => ['path' => 'Observers', 'generate' => false], 'observer' => ['path' => 'app/Observers', 'generate' => false],
'policies' => ['path' => 'Policies', 'generate' => false], 'policies' => ['path' => 'app/Policies', 'generate' => false],
'provider' => ['path' => 'Providers', 'generate' => true], 'provider' => ['path' => 'app/Providers', 'generate' => true],
'route-provider' => ['path' => 'Providers', 'generate' => true], 'route-provider' => ['path' => 'app/Providers', 'generate' => true],
'repository' => ['path' => 'Repositories', 'generate' => true], 'repository' => ['path' => 'app/Repositories', 'generate' => true],
'resource' => ['path' => 'Transformers', 'generate' => false], 'resource' => ['path' => 'app/Transformers', 'generate' => false],
'rules' => ['path' => 'Rules', 'generate' => false], 'rules' => ['path' => 'app/Rules', 'generate' => false],
'component-class' => ['path' => 'View/Components', 'generate' => false], 'component-class' => ['path' => 'app/View/Components', 'generate' => false],
// Http/ // app/Http/
'controller' => ['path' => 'Http/Controllers', 'generate' => true], 'controller' => ['path' => 'app/Http/Controllers', 'generate' => true],
'filter' => ['path' => 'Http/Middleware', 'generate' => false], 'filter' => ['path' => 'app/Http/Middleware', 'generate' => false],
'request' => ['path' => 'Http/Requests', 'generate' => false], 'request' => ['path' => 'app/Http/Requests', 'generate' => true],
// config/ // config/
'config' => ['path' => 'config', 'generate' => true], 'config' => ['path' => 'config', 'generate' => true],
@ -141,7 +141,7 @@ return [
// database/ // database/
'migration' => ['path' => 'database/migrations', 'generate' => true], 'migration' => ['path' => 'database/migrations', 'generate' => true],
'seeder' => ['path' => 'database/seeders', 'generate' => true], 'seeder' => ['path' => 'database/seeders', 'generate' => true],
'factory' => ['path' => 'database/factories', 'generate' => false], 'factory' => ['path' => 'database/factories', 'generate' => true],
// lang/ // lang/
'lang' => ['path' => 'lang', 'generate' => false], 'lang' => ['path' => 'lang', 'generate' => false],

View File

@ -4,6 +4,7 @@ namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents; // use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Permission; use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role; use Spatie\Permission\Models\Role;
@ -19,11 +20,15 @@ class DatabaseSeeder extends Seeder
$admin = \App\Models\User::factory()->create([ $admin = \App\Models\User::factory()->create([
'name' => 'Admin User', 'name' => 'Admin User',
'email' => 'admin@gmail.com', 'email' => 'admin@gmail.com',
'password' => Hash::make('password'),
]); ]);
$member = \App\Models\User::factory()->create([ $member = \App\Models\User::factory()->create([
'name' => 'Member User', 'name' => 'Member User',
'email' => 'member@gmail.com', 'email' => 'member@gmail.com',
'password' => Hash::make('password'),
]); ]);
$adminRole = Role::create(['name' => 'admin']); $adminRole = Role::create(['name' => 'admin']);

View File

@ -65,7 +65,7 @@
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link menu-link" href="{{ route('leave.index') }}"> <a class="nav-link menu-link active" href="{{ route('leave.index') }}">
<i class="ri-honour-line"></i> <span data-key="t-widgets">Leave</span> <i class="ri-honour-line"></i> <span data-key="t-widgets">Leave</span>
</a> </a>
</li> </li>