repository = $subcategory; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Classifieds\Category\Repositories\Criteria\SubcategoryResourceCriteria::class); } /** * Display a list of subcategory. * * @return Response */ public function index(SubcategoryRequest $request) { return $this->repository ->setPresenter(\Classifieds\Category\Repositories\Presenter\SubcategoryPresenter::class) ->paginate(); } /** * Display subcategory. * * @param Request $request * @param Model $subcategory * * @return Response */ public function show(SubcategoryRequest $request, Subcategory $subcategory) { return $subcategory->setPresenter(\Classifieds\Category\Repositories\Presenter\SubcategoryListPresenter::class); ; } /** * Create new subcategory. * * @param Request $request * * @return Response */ public function store(SubcategoryRequest $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('category::subcategory.name')]); $code = 204; $status = 'success'; $url = guard_url('category/subcategory/' . $subcategory->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('category/subcategory'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the subcategory. * * @param Request $request * @param Model $subcategory * * @return Response */ public function update(SubcategoryRequest $request, Subcategory $subcategory) { try { $data = $request->all(); $subcategory->update($data); $message = trans('messages.success.updated', ['Module' => trans('category::subcategory.name')]); $code = 204; $status = 'success'; $url = guard_url('category/subcategory/' . $subcategory->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('category/subcategory/' . $subcategory->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the subcategory. * * @param Model $subcategory * * @return Response */ public function destroy(SubcategoryRequest $request, Subcategory $subcategory) { try { $subcategory->delete(); $message = trans('messages.success.deleted', ['Module' => trans('category::subcategory.name')]); $code = 202; $status = 'success'; $url = guard_url('category/subcategory/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('category/subcategory/' . $subcategory->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); } }