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