form = CampaignForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('litecms.marketing.modules'), 'marketing', guard_url('marketing')); } /** * Display a list of campaign. * * @return Response */ public function index(CampaignResourceRequest $request) { $request = $request->all(); $page = CampaignActions::run('paginate', $request); $data = new CampaignsCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('marketing::campaign.names')) ->view('marketing::campaign.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display campaign. * * @param Request $request * @param Model $campaign * * @return Response */ public function show(CampaignResourceRequest $request, Campaign $model) { $form = $this->form; $modules = $this->modules; $data = new CampaignResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('marketing::campaign.name')) ->data(compact('data', 'form', 'modules')) ->view('marketing::campaign.show') ->output(); } /** * Show the form for creating a new campaign. * * @param Request $request * * @return Response */ public function create(CampaignResourceRequest $request, Campaign $model) { $form = $this->form; $modules = $this->modules; $data = new CampaignResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('marketing::campaign.name')) ->view('marketing::campaign.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new campaign. * * @param Request $request * * @return Response */ public function store(CampaignResourceRequest $request, Campaign $model) { try { $request = $request->all(); $model = CampaignAction::run('store', $model, $request); $data = new CampaignResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('marketing::campaign.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('marketing/campaign/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/marketing/campaign')) ->redirect(); } } /** * Show campaign for editing. * * @param Request $request * @param Model $campaign * * @return Response */ public function edit(CampaignResourceRequest $request, Campaign $model) { $form = $this->form; $modules = $this->modules; $data = new CampaignResource($model); // return view('marketing::campaign.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('marketing::campaign.name')) ->view('marketing::campaign.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the campaign. * * @param Request $request * @param Model $campaign * * @return Response */ public function update(CampaignResourceRequest $request, Campaign $model) { try { $request = $request->all(); $model = CampaignAction::run('update', $model, $request); $data = new CampaignResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('marketing::campaign.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('marketing/campaign/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('marketing/campaign/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the campaign. * * @param Model $campaign * * @return Response */ public function destroy(CampaignResourceRequest $request, Campaign $model) { try { $request = $request->all(); $model = CampaignAction::run('destroy', $model, $request); $data = new CampaignResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('marketing::campaign.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('marketing/campaign/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('marketing/campaign/' . $model->getRouteKey())) ->redirect(); } } }