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