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