diff --git a/Modules/Employee/app/Http/Controllers/EmployeeController.php b/Modules/Employee/app/Http/Controllers/EmployeeController.php index 8d9da57..3fdb764 100644 --- a/Modules/Employee/app/Http/Controllers/EmployeeController.php +++ b/Modules/Employee/app/Http/Controllers/EmployeeController.php @@ -3,13 +3,13 @@ namespace Modules\Employee\Http\Controllers; use App\Http\Controllers\Controller; -use App\Models\Role; use Carbon\Carbon; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; use Modules\Employee\Repositories\EmployeeInterface; use Modules\User\Repositories\UserInterface; +use Spatie\Permission\Models\Role; class EmployeeController extends Controller { @@ -53,6 +53,7 @@ class EmployeeController extends Controller */ public function store(Request $request) { + dd($request->all()); $inputData = $request->all(); try { @@ -63,8 +64,11 @@ class EmployeeController extends Controller } $this->employeeRepository->create($inputData); + toastr()->success('Employee Created Succesfully'); + } catch (\Throwable $th) { + echo $th->getMessage(); toastr()->error($th->getMessage()); } return redirect()->route('employee.index'); @@ -114,19 +118,25 @@ class EmployeeController extends Controller /** * Remove the specified resource from storage. */ - public function destroy($id) + public function destroy(Request $request) { try { - $employeeModel = $this->employeeRepository->getEmployeeById($id); - $employeeModel->user->roles()->detach(); - $employeeModel->user->delete(); - $employeeModel->delete(); + + $employeeModel = $this->employeeRepository->getEmployeeById($request->id); + + optional($employeeModel)->user?->roles()?->detach(); + + optional($employeeModel)->user?->delete(); + + optional($employeeModel)->delete(); + toastr()->success('Employee Delete Succesfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } - return redirect()->route('employee.index'); + + return response()->json(['status' => true, 'message' => 'Employee Delete Succesfully']); } @@ -153,4 +163,14 @@ class EmployeeController extends Controller return redirect()->route('employee.index'); } + public function changePassword(Request $request) + { + dd($request->all()); + try { + + } catch (\Throwable $th) { + toastr()->error($th->getMessage()); + } + } + } diff --git a/Modules/Employee/resources/views/index.blade.php b/Modules/Employee/resources/views/index.blade.php index adb94d1..bd7d1a0 100644 --- a/Modules/Employee/resources/views/index.blade.php +++ b/Modules/Employee/resources/views/index.blade.php @@ -42,7 +42,8 @@ @forelse ($employees as $employee)