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