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