Feuerwehr-eppingen/app/Jobs/MailAdminStatistics.php

68 lines
1.7 KiB
PHP

<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Mail\Mailer;
use App\Models\User;
use \Carbon\Carbon;
class MailAdminStatistics implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $template;
protected $posts;
protected $title;
protected $count;
protected $debug;
protected $debugText;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($template, $posts, $title, $count, $debug = false, $debugText = '')
{
$this->template = $template;
$this->posts = $posts;
$this->title = $title;
$this->count = $count;
$this->debug = $debug;
$this->debugText = $debugText;
}
/**
* Execute the job.
*
* @return void
*/
public function handle(Mailer $mailer)
{
$template = $this->template;
$posts = $this->posts;
$title = $this->title;
$count = $this->count;
$debugText = $this->debugText;
$admin = User::select('email')
->where('name', 'Admin')
->get();
$email = $admin[0]->email;
$emailFrom = config('mail.from.address');
echo "Sende Bericht an Admin: $email\n";
$mailer->send($template, ['departments' => $posts, 'debugText' => $debugText], function($message) use($email, $count, $title, $emailFrom){
$message->to($email)
->from($emailFrom, "Feuerwehr Eppingen - Gesamtwehr")
->subject("$title vom ".Carbon::now()->format('d.m.Y')." ($count)");
// ->subject("Feuerwehr Eppingen: Gesamtwehr - $title vom ".Carbon::now()->format('d.m.Y')." ($count)");
});
}
}