middleware(function ($request, $next) { $this->form = SubcategoryForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('classifieds.subcategory.modules'), 'subcategory', guard_url('subcategory')); return $next($request); }); } /** * Display a list of subcategory. * * @return Response */ public function index(SubcategoryResourceRequest $request) { $request = $request->all(); $page = SubcategoryActions::run('paginate', $request); $data = new SubcategoriesCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('subcategory::subcategory.names')) ->view('subcategory::subcategory.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display subcategory. * * @param Request $request * @param Model $subcategory * * @return Response */ public function show(SubcategoryResourceRequest $request, Subcategory $model) { $form = $this->form; $modules = $this->modules; $data = new SubcategoryResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('subcategory::subcategory.name')) ->data(compact('data', 'form', 'modules')) ->view('subcategory::subcategory.show') ->output(); } /** * Show the form for creating a new subcategory. * * @param Request $request * * @return Response */ public function create(SubcategoryResourceRequest $request, Subcategory $model) { $form = $this->form; $modules = $this->modules; $data = new SubcategoryResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('subcategory::subcategory.name')) ->view('subcategory::subcategory.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new subcategory. * * @param Request $request * * @return Response */ public function store(SubcategoryResourceRequest $request, Subcategory $model) { try { $request = $request->all(); $model = SubcategoryAction::run('store', $model, $request); $data = new SubcategoryResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('subcategory::subcategory.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('subcategory/subcategory/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/subcategory/subcategory')) ->redirect(); } } /** * Show subcategory for editing. * * @param Request $request * @param Model $subcategory * * @return Response */ public function edit(SubcategoryResourceRequest $request, Subcategory $model) { $form = $this->form; $modules = $this->modules; $data = new SubcategoryResource($model); // return view('subcategory::subcategory.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('subcategory::subcategory.name')) ->view('subcategory::subcategory.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the subcategory. * * @param Request $request * @param Model $subcategory * * @return Response */ public function update(SubcategoryResourceRequest $request, Subcategory $model) { try { $request = $request->all(); $model = SubcategoryAction::run('update', $model, $request); $data = new SubcategoryResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('subcategory::subcategory.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('subcategory/subcategory/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('subcategory/subcategory/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the subcategory. * * @param Model $subcategory * * @return Response */ public function destroy(SubcategoryResourceRequest $request, Subcategory $model) { try { $request = $request->all(); $model = SubcategoryAction::run('destroy', $model, $request); $data = new SubcategoryResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('subcategory::subcategory.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('subcategory/subcategory/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('subcategory/subcategory/' . $model->getRouteKey())) ->redirect(); } } }