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