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