repository = $salary; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Payroll\Salary\Repositories\Criteria\SalaryUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(SalaryRequest $request) { $salaries = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('salary::salary.names')); return $this->theme->of('salary::user.salary.index', compact('salaries'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Salary $salary * * @return Response */ public function show(SalaryRequest $request, Salary $salary) { Form::populate($salary); return $this->theme->of('salary::user.salary.show', compact('salary'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(SalaryRequest $request) { $salary = $this->repository->newInstance([]); Form::populate($salary); $this->theme->prependTitle(trans('salary::salary.names')); return $this->theme->of('salary::user.salary.create', compact('salary'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(SalaryRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $salary = $this->repository->create($attributes); return redirect(trans_url('/user/salary/salary')) -> with('message', trans('messages.success.created', ['Module' => trans('salary::salary.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Salary $salary * * @return Response */ public function edit(SalaryRequest $request, Salary $salary) { Form::populate($salary); $this->theme->prependTitle(trans('salary::salary.names')); return $this->theme->of('salary::user.salary.edit', compact('salary'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Salary $salary * * @return Response */ public function update(SalaryRequest $request, Salary $salary) { try { $this->repository->update($request->all(), $salary->getRouteKey()); return redirect(trans_url('/user/salary/salary')) ->with('message', trans('messages.success.updated', ['Module' => trans('salary::salary.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(SalaryRequest $request, Salary $salary) { try { $this->repository->delete($salary->getRouteKey()); return redirect(trans_url('/user/salary/salary')) ->with('message', trans('messages.success.deleted', ['Module' => trans('salary::salary.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }