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