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