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