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