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