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