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