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