form = AdvertisementForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('litecms.advertisement.modules'), 'advertisement', guard_url('advertisement')); } /** * Display a list of advertisement. * * @return Response */ public function index(AdvertisementRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = Advertisement::pushScope(new RequestScope()) ->pushScope(new AdvertisementResourceScope()) ->simplePaginate($pageLimit); $data = new AdvertisementsCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('advertisement::advertisement.names')) ->view('advertisement::advertisement.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display advertisement. * * @param Request $request * @param Model $advertisement * * @return Response */ public function show(AdvertisementRequest $request, Advertisement $model) { $form = $this->form; $modules = $this->modules; $data = new AdvertisementResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('advertisement::advertisement.name')) ->data(compact('data', 'form', 'modules')) ->view('advertisement::advertisement.show') ->output(); } /** * Show the form for creating a new advertisement. * * @param Request $request * * @return Response */ public function create(AdvertisementRequest $request, Advertisement $model) { $form = $this->form; $modules = $this->modules; $data = new AdvertisementResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('advertisement::advertisement.name')) ->view('advertisement::advertisement.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new advertisement. * * @param Request $request * * @return Response */ public function store(AdvertisementRequest $request, Advertisement $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new AdvertisementResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('advertisement::advertisement.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('advertisement/advertisement/' . $model->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 $model) { $form = $this->form; $modules = $this->modules; $data = new AdvertisementResource($model); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('advertisement::advertisement.name')) ->view('advertisement::advertisement.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the advertisement. * * @param Request $request * @param Model $advertisement * * @return Response */ public function update(AdvertisementRequest $request, Advertisement $model) { try { $attributes = $request->all(); $model = $model->update($attributes); $data = new AdvertisementResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('advertisement::advertisement.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('advertisement/advertisement/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('advertisement/advertisement/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the advertisement. * * @param Model $advertisement * * @return Response */ public function destroy(AdvertisementRequest $request, Advertisement $model) { try { $model->delete(); $data = new AdvertisementResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('advertisement::advertisement.name')])) ->code(202) ->status('success') ->data(compact('data')) ->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/' . $model->getRouteKey())) ->redirect(); } } }