leaveRepository = $leaveRepository; $this->employeeRepository = $employeeRepository; $this->leaveTypeRepository = $leaveTypeRepository; $this->middleware('role_or_permission:access leaves|create leaves|edit leaves|delete leaves', ['only' => ['index', 'show']]); $this->middleware('role_or_permission:create leaves', ['only' => ['create', 'store']]); $this->middleware('role_or_permission:edit leaves', ['only' => ['edit', 'update']]); $this->middleware('role_or_permission:delete leaves', ['only' => ['destroy']]); } /** * Display a listing of the resource. */ public function index() { $data['leaves'] = $this->leaveRepository->findAll(); $data['employeeList'] = $this->employeeRepository->pluck(); return view('leave::leave.index', $data); } /** * Show the form for creating a new resource. */ public function create() { $data['title'] = 'Create Leave'; $data['editable'] = false; $data['employeeList'] = $this->employeeRepository->pluck(); $data['leaveTypeList'] = $this->leaveTypeRepository->pluck(); return view('leave::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::leave.show'); } /** * Show the form for editing the specified resource. */ public function edit($id) { $data['title'] = 'Edit Leave'; $data['editable'] = true; $data['leave'] = $this->leaveRepository->getLeaveById($id); return view('leave::leave.edit', $data); } /** * Update the specified resource in storage. */ public function update(Request $request, $id): RedirectResponse { $inputData = $request->all(); try { $this->leaveRepository->update($id, $inputData); toastr()->success('Leave Updated Succesfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return redirect()->route('leave.index'); } /** * Remove the specified resource from storage. */ public function destroy($id) { try { $this->leaveRepository->delete($id); toastr()->success('Leave Deleted Succesfully'); } catch (\Throwable $th) { //throw $th; toastr()->error($th->getMessage()); } } }