/**
  * Handle the event.
  *
  * @param  PaperWasCreated $event
  * @return void
  */
 public function handle(PaperWasCreated $event)
 {
     $template = new Template();
     $settings = $event->paper->department->settings()->key('email_add_paper');
     if (isset($settings->value) && $settings->value) {
         $emailTemplate = EmailTemplate::findOrFail($settings->value);
         $emailTemplate->body = $template->parser($emailTemplate->body, ['name' => $event->paper->user->name, 'time' => $event->paper->created_at, 'link' => buildPaperLink($event->paper)]);
         $this->mailer->send('layouts.partials.email', ['body' => $emailTemplate->body], function ($message) use($emailTemplate, $event) {
             $message->subject($emailTemplate->subject);
             $message->to($event->paper->user->email);
         });
     }
 }
 /**
  * Handle the event.
  *
  * @param  PaperWasCreated  $event
  * @return void
  */
 public function handle($event)
 {
     $template = new Template();
     $department = $event->paper->department;
     $settings = $department->settings()->key('email_notification');
     if (isset($settings->value) && $settings->value) {
         $users = User::where('department_id', $department->id)->whereHas('type.access', function ($query) {
             $query->where('access_id', 12);
         })->get();
         if (count($users)) {
             $emailTemplate = EmailTemplate::findOrFail($settings->value);
             $emails = $users->pluck('email')->toArray();
             $body = $template->parser($emailTemplate->body, ['author_name' => $event->paper->user->name, 'time' => $event->paper->updated_at, 'operation' => $event->operation, 'link' => action('Admin\\PaperController@show', [$event->paper->id])]);
             $this->mailer->send('layouts.partials.email', ['body' => $body], function ($message) use($emailTemplate, $emails) {
                 $message->subject($emailTemplate->subject);
                 $message->to($emails);
             });
         }
     }
 }
Esempio n. 3
0
 public function postEmail(Request $request, TokenRepositoryInterface $token)
 {
     $department = $this->getDepartment();
     $this->validate($request, ['email' => 'required|email|exists:users,email,department_id,' . $department->id]);
     $template = new Template();
     $user = User::where('email', $request->get('email'))->where('department_id', $department->id)->first();
     if (!$user) {
         return redirect()->back()->with('error', 'error');
     }
     $settings = $user->department->settings()->key('email_password_reset');
     if (!isset($settings->value) || !$settings->value) {
         return redirect()->back()->with('error', 'no-template');
     }
     $emailTemplate = EmailTemplate::findOrFail($settings->value);
     $emailTemplate->body = $template->parser($emailTemplate->body, ['name' => $user->name, 'expire' => Carbon::now()->addMinutes(config('auth.password.expire'))->format('d.m.Y H:i'), 'link' => route('department::auth::reset_token', $user->department->keyword) . '/' . $token->create($user)]);
     Mail::send('layouts.partials.email', ['body' => $emailTemplate->body], function ($message) use($emailTemplate, $user) {
         $message->subject($emailTemplate->subject);
         $message->to($user->email);
     });
     return redirect()->back()->with('success', 'email-send');
 }