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