repository = $return; parent::__construct(); } /** * Display a list of return. * * @return Response */ public function index(ReturnRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('return::return.names').' :: '); return $this->theme->of('return::admin.return.index')->render(); } /** * Display a list of return. * * @return Response */ public function getJson(ReturnRequest $request) { $pageLimit = $request->input('pageLimit'); $returns = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Laracart\\Return\\Repositories\\Presenter\\ReturnListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $returns['recordsTotal'] = $returns['meta']['pagination']['total']; $returns['recordsFiltered'] = $returns['meta']['pagination']['total']; $returns['request'] = $request->all(); return response()->json($returns, 200); } /** * Display return. * * @param Request $request * @param Model $return * * @return Response */ public function show(ReturnRequest $request, Return $return) { if (!$return->exists) { return response()->view('return::admin.return.new', compact('return')); } Form::populate($return); return response()->view('return::admin.return.show', compact('return')); } /** * Show the form for creating a new return. * * @param Request $request * * @return Response */ public function create(ReturnRequest $request) { $return = $this->repository->newInstance([]); Form::populate($return); return response()->view('return::admin.return.create', compact('return')); } /** * Create new return. * * @param Request $request * * @return Response */ public function store(ReturnRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $return = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('return::return.name')]), 'code' => 204, 'redirect' => trans_url('/admin/return/return/'.$return->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show return for editing. * * @param Request $request * @param Model $return * * @return Response */ public function edit(ReturnRequest $request, Return $return) { Form::populate($return); return response()->view('return::admin.return.edit', compact('return')); } /** * Update the return. * * @param Request $request * @param Model $return * * @return Response */ public function update(ReturnRequest $request, Return $return) { try { $attributes = $request->all(); $return->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('return::return.name')]), 'code' => 204, 'redirect' => trans_url('/admin/return/return/'.$return->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/return/return/'.$return->getRouteKey()), ], 400); } } /** * Remove the return. * * @param Model $return * * @return Response */ public function destroy(ReturnRequest $request, Return $return) { try { $t = $return->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('return::return.name')]), 'code' => 202, 'redirect' => trans_url('/admin/return/return/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/return/return/'.$return->getRouteKey()), ], 400); } } }