leaveRepository = $leaveRepository; $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(); return view('leave::index',$data); } /** * Show the form for creating a new resource. */ public function create() { $data['title'] = 'Create Leave'; return view('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::show'); } /** * Show the form for editing the specified resource. */ public function edit($id) { $data['title'] = 'Edit Leave'; $data['leave'] = $this->leaveRepository->getLeaveById($id); return view('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) { $this->leaveRepository->delete($id); toastr()->success('Leave Deleted Succesfully'); } }