From 6b6696ded4568fc08c1f827cc172683d9b2eb2f1 Mon Sep 17 00:00:00 2001 From: Ranjan Date: Sun, 7 Apr 2024 17:39:18 +0545 Subject: [PATCH] employee module --- .../Http/Controllers/EmployeeController.php | 52 ++- Modules/Employee/app/Models/Employee.php | 13 + .../app/Providers/EmployeeServiceProvider.php | 17 +- .../app/Repositories/EmployeeInterface.php | 12 + .../app/Repositories/EmployeeRepository.php | 49 +++ ...24_04_07_093523_create_employees_table.php | 61 ++++ .../Employee/resources/views/create.blade.php | 11 +- .../Employee/resources/views/edit.blade.php | 22 ++ .../Employee/resources/views/index.blade.php | 281 ++++++-------- .../resources/views/partials/action.blade.php | 342 ++++++------------ 10 files changed, 433 insertions(+), 427 deletions(-) create mode 100644 Modules/Employee/app/Models/Employee.php create mode 100644 Modules/Employee/app/Repositories/EmployeeInterface.php create mode 100644 Modules/Employee/app/Repositories/EmployeeRepository.php create mode 100644 Modules/Employee/database/migrations/2024_04_07_093523_create_employees_table.php create mode 100644 Modules/Employee/resources/views/edit.blade.php diff --git a/Modules/Employee/app/Http/Controllers/EmployeeController.php b/Modules/Employee/app/Http/Controllers/EmployeeController.php index b911669..6bf2ae0 100644 --- a/Modules/Employee/app/Http/Controllers/EmployeeController.php +++ b/Modules/Employee/app/Http/Controllers/EmployeeController.php @@ -5,15 +5,24 @@ namespace Modules\Employee\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Modules\Employee\Repositories\EmployeeInterface; class EmployeeController extends Controller { + + private EmployeeInterface $employeeRepository; + + public function __construct(EmployeeInterface $employeeRepository) + { + $this->employeeRepository = $employeeRepository; + } /** * Display a listing of the resource. */ public function index() { - return view('employee::index'); + $data['employees'] = $this->employeeRepository->findAll(); + return view('employee::index', $data); } /** @@ -28,9 +37,25 @@ class EmployeeController extends Controller /** * Store a newly created resource in storage. */ - public function store(Request $request): RedirectResponse + public function store(Request $request) { - // + $inputData = $request->only(['first_name', 'last_name']); + // try { + + if ($request->hasFile('profile_pic')) { + $fileName = time() . '_' . $request->profile_pic->getClientOriginalName(); + $filePath = $request->file('profile_pic')->storeAs('uploads', $fileName, 'public'); + $inputData['profile_picture'] = time() . '_' . $request->profile_pic->getClientOriginalName(); + // $fileModel->file_path = '/storage/' . $filePath; + // $fileModel->save(); + } + + $this->employeeRepository->create($inputData); + toastr()->success('Employee Created Succesfully'); + // } catch (\Throwable $th) { + // toastr()->error($th->getMessage()); + // } + return redirect()->route('employee.index'); } /** @@ -38,6 +63,7 @@ class EmployeeController extends Controller */ public function show($id) { + return view('employee::show'); } @@ -46,7 +72,9 @@ class EmployeeController extends Controller */ public function edit($id) { - return view('employee::edit'); + $data['title'] = 'Edit Employee'; + $data['employee'] = $this->employeeRepository->getEmployeeById($id); + return view('employee::edit', $data); } /** @@ -54,7 +82,21 @@ class EmployeeController extends Controller */ public function update(Request $request, $id): RedirectResponse { - // + $inputData = $request->only(['first_name', 'last_name']); + // try { + + if ($request->hasFile('profile_pic')) { + $fileName = time() . '_' . $request->profile_pic->getClientOriginalName(); + $filePath = $request->file('profile_pic')->storeAs('uploads', $fileName, 'public'); + $inputData['profile_picture'] = time() . '_' . $request->profile_pic->getClientOriginalName(); + } + + $this->employeeRepository->update($id, $inputData); + toastr()->success('Employee Created Succesfully'); + // } catch (\Throwable $th) { + // toastr()->error($th->getMessage()); + // } + return redirect()->route('employee.index'); } /** diff --git a/Modules/Employee/app/Models/Employee.php b/Modules/Employee/app/Models/Employee.php new file mode 100644 index 0000000..40dfe5f --- /dev/null +++ b/Modules/Employee/app/Models/Employee.php @@ -0,0 +1,13 @@ +app->bind(EmployeeInterface::class, EmployeeRepository::class); $this->app->register(RouteServiceProvider::class); } @@ -56,7 +59,7 @@ class EmployeeServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/' . $this->moduleNameLower); if (is_dir($langPath)) { $this->loadTranslationsFrom($langPath, $this->moduleNameLower); @@ -72,7 +75,7 @@ class EmployeeServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $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); } @@ -81,14 +84,14 @@ class EmployeeServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $viewPath = resource_path('views/modules/' . $this->moduleNameLower); $sourcePath = module_path($this->moduleName, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-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',''))); + $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); } @@ -104,8 +107,8 @@ class EmployeeServiceProvider extends ServiceProvider { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path . '/modules/' . $this->moduleNameLower)) { + $paths[] = $path . '/modules/' . $this->moduleNameLower; } } diff --git a/Modules/Employee/app/Repositories/EmployeeInterface.php b/Modules/Employee/app/Repositories/EmployeeInterface.php new file mode 100644 index 0000000..274637e --- /dev/null +++ b/Modules/Employee/app/Repositories/EmployeeInterface.php @@ -0,0 +1,12 @@ +update($newDetails); + } + + // public function uploadImage($file) + // { + // if ($req->file()) { + // $fileName = time() . '_' . $req->file->getClientOriginalName(); + // $filePath = $req->file('file')->storeAs('uploads', $fileName, 'public'); + // $fileModel->name = time() . '_' . $req->file->getClientOriginalName(); + // $fileModel->file_path = '/storage/' . $filePath; + // $fileModel->save(); + // return back() + // ->with('success', 'File has been uploaded.') + // ->with('file', $fileName); + // } + // } + +} diff --git a/Modules/Employee/database/migrations/2024_04_07_093523_create_employees_table.php b/Modules/Employee/database/migrations/2024_04_07_093523_create_employees_table.php new file mode 100644 index 0000000..e2a9103 --- /dev/null +++ b/Modules/Employee/database/migrations/2024_04_07_093523_create_employees_table.php @@ -0,0 +1,61 @@ +id(); + $table->string('first_name')->nullable(); + $table->string('middle_name')->nullable(); + $table->string('last_name')->nullable(); + $table->string('email')->nullable(); + $table->unsignedBigInteger('genders_id')->nullable(); + $table->date('nepali_dob')->nullable(); + $table->date('dob')->nullable(); + $table->unsignedBigInteger('nationalities_id')->nullable(); + $table->text('about_me')->nullable(); + $table->string('signature')->nullable(); + $table->string('father_name')->nullable(); + $table->string('mother_name')->nullable(); + $table->string('grand_father_name')->nullable(); + $table->string('grand_mother_name')->nullable(); + $table->string('spouse')->nullable(); + $table->string('contact')->nullable(); + $table->string('alt_contact')->nullable(); + $table->string('profile_picture')->nullable(); + $table->unsignedBigInteger('users_id')->nullable(); + $table->text('skills')->nullable(); + $table->text('experience')->nullable(); + $table->text('permanent_address')->nullable(); + $table->unsignedBigInteger('permanent_city')->nullable(); + $table->text('temporary_address')->nullable(); + $table->unsignedBigInteger('temporary_city')->nullable(); + $table->text('old_system_address')->nullable(); + $table->text('education')->nullable(); + $table->unsignedBigInteger('castes_id')->nullable(); + $table->unsignedBigInteger('ethnicities_id')->nullable(); + $table->unsignedBigInteger('dags_id')->nullable(); + $table->string('status')->nullable(); + $table->string('remarks')->nullable(); + $table->unsignedBigInteger('createdby')->nullable(); + $table->unsignedBigInteger('updatedby')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('employees'); + } +}; diff --git a/Modules/Employee/resources/views/create.blade.php b/Modules/Employee/resources/views/create.blade.php index f57f6e4..e72d787 100644 --- a/Modules/Employee/resources/views/create.blade.php +++ b/Modules/Employee/resources/views/create.blade.php @@ -7,14 +7,9 @@ @include('layouts.partials.breadcrumb', ['title' => $title]) - -
- @csrf - @include('employee::partials.action') -
- - - + {{ html()->form('POST')->route('employee.store')->class(['needs-validation'])->attributes(['novalidate', 'enctype' => 'multipart/form-data'])->open() }} + @include('employee::partials.action') + {{ html()->form()->close() }} diff --git a/Modules/Employee/resources/views/edit.blade.php b/Modules/Employee/resources/views/edit.blade.php new file mode 100644 index 0000000..c8e0834 --- /dev/null +++ b/Modules/Employee/resources/views/edit.blade.php @@ -0,0 +1,22 @@ +@extends('layouts.app') + +@section('content') +
+
+ + @include('layouts.partials.breadcrumb', ['title' => $title]) + + + {{-- {{ html()->form('POST')->route('employee.store')->class(['needs-validation'])->attributes(['novalidate', 'enctype' => 'multipart/form-data'])->open() }} --}} + {{ html()->modelForm($employee, 'PUT')->route('employee.update', $employee->id)->class(['needs-validation'])->attributes(['novalidate', 'enctype' => 'multipart/form-data'])->open() }} + @include('employee::partials.action') + {{ html()->closeModelForm() }} + +
+ +
+@endsection + +@push('js') + +@endpush diff --git a/Modules/Employee/resources/views/index.blade.php b/Modules/Employee/resources/views/index.blade.php index 8f755f4..baa1a40 100644 --- a/Modules/Employee/resources/views/index.blade.php +++ b/Modules/Employee/resources/views/index.blade.php @@ -39,187 +39,67 @@
- -
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
Nancy Martino
-
-

Team Leader & HR

-
-
-
-
-
-
-
225
-

Projects

-
-
-
197
-

Tasks

-
-
-
- + @forelse ($employees as $employee) +
+
+
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
HB +
+
Active
+
+
+ -
-
Henry Baird
-
-

Full Stack Developer

-
-
-
-
-
-
352
-

Projects

-
-
-
376
-

Tasks

+ {{--
+
+
+
225
+

Projects

+
+
+
197
+

Tasks

+
+
--}} +
+
-
-
+ @endforeach -
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
Frank Hook
-
-

Project Manager

-
-
-
-
-
-
-
164
-

Projects

-
-
-
182
-

Tasks

-
-
-
- -
-
-
-
@@ -228,4 +108,65 @@
+ + + + @endsection diff --git a/Modules/Employee/resources/views/partials/action.blade.php b/Modules/Employee/resources/views/partials/action.blade.php index 7c316c4..070f966 100644 --- a/Modules/Employee/resources/views/partials/action.blade.php +++ b/Modules/Employee/resources/views/partials/action.blade.php @@ -1,11 +1,11 @@
-
+

Personal Details

-
+
{{ html()->label('First name')->class('form-label') }} @@ -18,18 +18,44 @@
- - + {{ html()->label('Last name')->class('form-label') }} + {{ html()->text('last_name')->class('form-control')->placeholder('Enter Last Name')->required() }} + {{ html()->div('Please enter last name')->class('invalid-feedback') }}
- - + {{ html()->label('Gender')->class('form-label') }} + {{ html()->select('gender', ['male', 'female'])->class('form-select')->placeholder('Select Gender') }}
+
+ {{ html()->label('Date of Birth')->class('form-label') }} + {{ html()->date('dob')->class('form-control')->placeholder('Choose Date of Birth')->required() }} + {{ html()->div('Please choose dob')->class('invalid-feedback') }} +
+
+ {{ html()->label('Nationality')->class('form-label') }} + {{ html()->select('nationality', ['Nepal', 'Other'])->class('form-control')->placeholder('Select Nationality') }} +
+ +
+ {{ html()->label('Email')->class('form-label') }} + {{ html()->email('email')->class('form-control')->placeholder('Enter Email')->required() }} + {{ html()->div('Please enter email')->class('invalid-feedback') }} +
+ +
+ {{ html()->label('Phone Number')->class('form-label') }} + {{ html()->text('phone')->class('form-control')->placeholder('Enter Phone Number') }} +
+ +
+ {{ html()->label('Upload Profile Pic')->class('form-label') }} + {{ html()->file('profile_pic')->class('form-control') }} + +
@@ -37,243 +63,85 @@
-
-
Attached files
+
+
Address Detail
-
-
-

Add Attached files here.

+
+ {{--
+ {{ html()->label('Country')->class('form-label') }} + {{ html()->select('country_id', ['Nepal'])->class('form-select')->placeholder('Select Country') }} +
--}} -
- -
-
- -
- -
Drop files here or click to upload.
-
-
- -
    - -
- +
+ {{ html()->label('State')->class('form-label') }} + {{ html()->select('state_id', ['Nepal'])->class('form-select')->placeholder('Select State') }}
+ +
+ {{ html()->label('District name')->class('form-label') }} + {{ html()->select('district_id', [])->class('form-select')->placeholder('Select District') }} +
+ +
+ {{ html()->label('City')->class('form-label') }} + {{ html()->text('last_name')->class('form-control')->placeholder('Enter City Name') }} +
+ +
+ {{ html()->label('municipality')->class('form-label') }} + {{ html()->select('municipality_id', [])->class('form-select')->placeholder('Select Municipality') }} +
+ +
+ {{ html()->label('Ward')->class('form-label') }} + {{ html()->text('ward')->class('form-control')->placeholder('Enter Ward no') }} +
+ +
+ {{ html()->label('Permanent Address')->class('form-label') }} + {{ html()->text('perm_address')->class('form-control')->placeholder('Enter Permanent Address') }} +
+ +
+ {{ html()->label('Temporary Address')->class('form-label') }} + {{ html()->text('temp_address')->class('form-control')->placeholder('Enter Temporary Address') }} +
+ +
+
+ +
+
+
Organization Detail
+
+
+
+ {{ html()->label('Department')->class('form-label') }} + {{ html()->select('department_id', ['Nepal'])->class('form-select')->placeholder('Select Department') }} +
+ +
+ {{ html()->label('Designation')->class('form-label') }} + {{ html()->select('designation_id', ['Nepal'])->class('form-select')->placeholder('Select Designation') }} +
+ +
+ {{ html()->label('Join Date')->class('form-label') }} + {{ html()->date('join_date')->class('form-control')->placeholder('Choose Join Date') }} +
+ + +
+ {{ html()->label('Remarks')->class('form-label') }} + {{ html()->textarea('remark')->class('form-control')->placeholder('Enter Remarks') }} +
+
-
- - - +
+
- -
-
-
-
Privacy
-
-
-
- - -
-
- -
- -
-
-
Tags
-
-
-
- - -
- -
- - -
-
- -
- - -
-
-
Members
-
-
-
- - -
- - -
- -
- -
-