employeeRepository = $employeeRepository; $this->userRepository = $userRepository; } /** * Display a listing of the resource. */ public function index() { $data['employees'] = $this->employeeRepository->findAll(); $data['roleLists'] = Role::pluck('name', 'id'); // dd($data['employees']->toArray()); return view('employee::index', $data); } /** * Show the form for creating a new resource. */ public function create() { $data['title'] = 'Create Employee'; $data['departmentList'] = []; $data['designationList'] = []; $data['genderList'] = []; $data['nationalityList'] = []; return view('employee::create', $data); } /** * Store a newly created resource in storage. */ public function store(Request $request) { dd($request->all()); $inputData = $request->all(); 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->create($inputData); toastr()->success('Employee Created Succesfully'); } catch (\Throwable $th) { echo $th->getMessage(); toastr()->error($th->getMessage()); } return redirect()->route('employee.index'); } /** * Show the specified resource. */ public function show($id) { $data['employee'] = $this->employeeRepository->getEmployeeById($id); return view('employee::show', $data); } /** * Show the form for editing the specified resource. */ public function edit($id) { $data['title'] = 'Edit Employee'; $data['employee'] = $this->employeeRepository->getEmployeeById($id); return view('employee::edit', $data); } /** * Update the specified resource in storage. */ public function update(Request $request, $id): RedirectResponse { $inputData = $request->except(['_method', '_token']); 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'); } /** * Remove the specified resource from storage. */ public function destroy(Request $request) { try { $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 response()->json(['status' => true, 'message' => 'Employee Delete Succesfully']); } public function assignRole(Request $request) { try { $employeeModel = $this->employeeRepository->getEmployeeByEmail($request->email); $inputData = [ 'name' => $employeeModel->first_name . ' ' . $employeeModel->last_name, 'email' => $request->email, 'password' => Hash::make('password'), 'email_verified_at' => Carbon::now(), ]; $userModel = $this->userRepository->create($inputData, [$request->role_id]); $employeeModel->users_id = $userModel->id; $employeeModel->save(); toastr()->success('Role Assigned Succesfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return redirect()->route('employee.index'); } public function changePassword(Request $request) { dd($request->all()); try { } catch (\Throwable $th) { toastr()->error($th->getMessage()); } } }