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