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