form = AdvertisementForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('crm.advertisement.modules'), 'advertisement', guard_url('advertisement')); } /** * Display a list of advertisement. * * @return Response */ public function index(AdvertisementResourceRequest $request) { $request = $request->all(); $page = AdvertisementActions::run('paginate', $request); $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(AdvertisementResourceRequest $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(AdvertisementResourceRequest $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(AdvertisementResourceRequest $request, Advertisement $model) { try { $request = $request->all(); $model = AdvertisementAction::run('store', $model, $request); $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(AdvertisementResourceRequest $request, Advertisement $model) { $form = $this->form; $modules = $this->modules; $data = new AdvertisementResource($model); // return view('advertisement::advertisement.edit', compact('data', 'form', 'modules')); 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(AdvertisementResourceRequest $request, Advertisement $model) { try { $request = $request->all(); $model = AdvertisementAction::run('update', $model, $request); $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(AdvertisementResourceRequest $request, Advertisement $model) { try { $request = $request->all(); $model = AdvertisementAction::run('destroy', $model, $request); $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(); } } }