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