mivita/app/Mail/MailSyS.php
2020-08-07 16:02:03 +02:00

63 lines
No EOL
1.8 KiB
PHP

<?php
namespace App\Mail;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class MailSyS extends Mailable
{
use Queueable, SerializesModels;
protected $model;
protected $action;
public $subject;
public function __construct($model, $action)
{
$this->model = $model;
$this->action = $action;
if($this->action === "log"){
$this->subject = 'mivita Logger';
}
}
public function build()
{
$content = "";
if($this->action === "log"){
$title = "New Log";
if($this->model->user_id && $this->model->user){
$content .= "From User: ".$this->model->user->id." | ".$this->model->user->email."\n";
}
if($this->model->model && $this->model->model_id){
$content .= "Apply: ".$this->model->model." | ".$this->model->model_id."\n";
if($this->model->model === 'App\User'){
$apply = User::find($this->model->model_id);
$content .= $this->model->model.": ".$apply->email." | ".$this->model->model_id."\n";
}
}
$content .= "\n";
$content .= "Action: ".$this->model->action."\n";
$content .= "Message: ".$this->model->message."\n";
$content .= "\n";
$content .= "Channel: ".$this->model->channel."\n";
$content .= "Level: ".$this->model->getLevelType()."\n";
$content .= "\n";
$content .= "Time: ".$this->model->created_at->format("d.m.Y H:i");
}
return $this->view('emails.sys')->with([
'title' => $title,
'content' => $content,
]);
}
}