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