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