repository = $b2buy; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\B2buy\Faq\Repositories\Criteria\B2buyResourceCriteria::class); } /** * Display a list of b2buy. * * @return Response */ public function index(B2buyRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\B2buy\Faq\Repositories\Presenter\B2buyPresenter::class) ->$function(); } $b2buys = $this->repository->paginate(); return $this->response->setMetaTitle(trans('faq::b2buy.names')) ->view('faq::b2buy.index', true) ->data(compact('b2buys', 'view')) ->output(); } /** * Display b2buy. * * @param Request $request * @param Model $b2buy * * @return Response */ public function show(B2buyRequest $request, B2buy $b2buy) { if ($b2buy->exists) { $view = 'faq::b2buy.show'; } else { $view = 'faq::b2buy.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('faq::b2buy.name')) ->data(compact('b2buy')) ->view($view, true) ->output(); } /** * Show the form for creating a new b2buy. * * @param Request $request * * @return Response */ public function create(B2buyRequest $request) { $b2buy = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('faq::b2buy.name')) ->view('faq::b2buy.create', true) ->data(compact('b2buy')) ->output(); } /** * Create new b2buy. * * @param Request $request * * @return Response */ public function store(B2buyRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $b2buy = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('faq::b2buy.name')])) ->code(204) ->status('success') ->url(guard_url('faq/b2buy/' . $b2buy->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/faq/b2buy')) ->redirect(); } } /** * Show b2buy for editing. * * @param Request $request * @param Model $b2buy * * @return Response */ public function edit(B2buyRequest $request, B2buy $b2buy) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('faq::b2buy.name')) ->view('faq::b2buy.edit', true) ->data(compact('b2buy')) ->output(); } /** * Update the b2buy. * * @param Request $request * @param Model $b2buy * * @return Response */ public function update(B2buyRequest $request, B2buy $b2buy) { try { $attributes = $request->all(); $b2buy->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('faq::b2buy.name')])) ->code(204) ->status('success') ->url(guard_url('faq/b2buy/' . $b2buy->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('faq/b2buy/' . $b2buy->getRouteKey())) ->redirect(); } } /** * Remove the b2buy. * * @param Model $b2buy * * @return Response */ public function destroy(B2buyRequest $request, B2buy $b2buy) { try { $b2buy->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('faq::b2buy.name')])) ->code(202) ->status('success') ->url(guard_url('faq/b2buy/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('faq/b2buy/' . $b2buy->getRouteKey())) ->redirect(); } } /** * Remove multiple b2buy. * * @param Model $b2buy * * @return Response */ public function delete(B2buyRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('faq::b2buy.name')])) ->status("success") ->code(202) ->url(guard_url('faq/b2buy')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/faq/b2buy')) ->redirect(); } } /** * Restore deleted b2buys. * * @param Model $b2buy * * @return Response */ public function restore(B2buyRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('faq::b2buy.name')])) ->status("success") ->code(202) ->url(guard_url('/faq/b2buy')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/faq/b2buy/')) ->redirect(); } } }