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