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]) - -
- - - + {{ 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') +Team Leader & HR
-Projects
-Tasks
-Bibhuti
Full Stack Developer
-Projects
-Tasks
+ {{--Projects
+Tasks
+Project Manager
-Projects
-Tasks
-Add Attached files here.
+