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