repository = $category; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Islhd\Product\Repositories\Criteria\CategoryResourceCriteria::class); } /** * Display a list of category. * * @return Response */ public function index(CategoryRequest $request) { return $this->repository ->setPresenter(\Islhd\Product\Repositories\Presenter\CategoryPresenter::class) ->paginate(); } /** * Display category. * * @param Request $request * @param Model $category * * @return Response */ public function show(CategoryRequest $request, Category $category) { return $category->setPresenter(\Islhd\Product\Repositories\Presenter\CategoryListPresenter::class); ; } /** * Create new category. * * @param Request $request * * @return Response */ public function store(CategoryRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('product::category.name')]); $code = 204; $status = 'success'; $url = guard_url('product/category/' . $category->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('product/category'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the category. * * @param Request $request * @param Model $category * * @return Response */ public function update(CategoryRequest $request, Category $category) { try { $data = $request->all(); $category->update($data); $message = trans('messages.success.updated', ['Module' => trans('product::category.name')]); $code = 204; $status = 'success'; $url = guard_url('product/category/' . $category->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('product/category/' . $category->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the category. * * @param Model $category * * @return Response */ public function destroy(CategoryRequest $request, Category $category) { try { $category->delete(); $message = trans('messages.success.deleted', ['Module' => trans('product::category.name')]); $code = 202; $status = 'success'; $url = guard_url('product/category/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('product/category/' . $category->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }