repository = $advertising; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Omid\OMID\Repositories\Criteria\AdvertisingResourceCriteria::class); } /** * Display a list of advertising. * * @return Response */ public function index(AdvertisingRequest $request) { if ($this->response->typeIs('json')) { $pageLimit = $request->input('pageLimit'); $data = $this->repository ->setPresenter(\Omid\OMID\Repositories\Presenter\AdvertisingListPresenter::class) ->getDataTable($pageLimit); return $this->response ->data($data) ->output(); } $advertisings = $this->repository->paginate(); return $this->response->title(trans('o_m_i_d::advertising.names')) ->view('o_m_i_d::advertising.index', true) ->data(compact('advertisings')) ->output(); } /** * Display advertising. * * @param Request $request * @param Model $advertising * * @return Response */ public function show(AdvertisingRequest $request, Advertising $advertising) { if ($advertising->exists) { $view = 'o_m_i_d::advertising.show'; } else { $view = 'o_m_i_d::advertising.new'; } return $this->response->title(trans('app.view') . ' ' . trans('o_m_i_d::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->title(trans('app.new') . ' ' . trans('o_m_i_d::advertising.name')) ->view('o_m_i_d::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('o_m_i_d::advertising.name')])) ->code(204) ->status('success') ->url(guard_url('o_m_i_d/advertising/' . $advertising->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/o_m_i_d/advertising')) ->redirect(); } } /** * Show advertising for editing. * * @param Request $request * @param Model $advertising * * @return Response */ public function edit(AdvertisingRequest $request, Advertising $advertising) { return $this->response->title(trans('app.edit') . ' ' . trans('o_m_i_d::advertising.name')) ->view('o_m_i_d::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('o_m_i_d::advertising.name')])) ->code(204) ->status('success') ->url(guard_url('o_m_i_d/advertising/' . $advertising->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('o_m_i_d/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('o_m_i_d::advertising.name')])) ->code(202) ->status('success') ->url(guard_url('o_m_i_d/advertising')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('o_m_i_d/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('o_m_i_d::advertising.name')])) ->status("success") ->code(202) ->url(guard_url('o_m_i_d/advertising')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/o_m_i_d/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('o_m_i_d::advertising.name')])) ->status("success") ->code(202) ->url(guard_url('/o_m_i_d/advertising')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/o_m_i_d/advertising/')) ->redirect(); } } }