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