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