File: D:/HostingSpaces/SBogers10/inzigd.komma.pro/app/Mail/AdminError.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Http\Request;
use Illuminate\Queue\SerializesModels;
class AdminError extends ConfigurableMailable
{
use Queueable, SerializesModels;
/**@var \Illuminate\Http\Request */
private $request;
/** @var \Exception */
private $exception;
/**
* @var int
*/
private $httpStatusCode;
/**
* Create a new message instance that represents a mail containing information about an exception
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @param int $httpStatusCode
*/
public function __construct(Request $request, \Exception $exception, int $httpStatusCode)
{
$this->request = $request;
$this->exception = $exception;
$this->httpStatusCode = $httpStatusCode;
parent::__construct();
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
//Prepare Exception for mailing
$requestUri = strtolower($this->request->getRequestUri());
$stackTrace = $this->makeStackTraceLookNicer(nl2br($this->exception->getTraceAsString()));
$errorMessage = $this->exception->getMessage();
//Build a subject
$subject = $this->httpStatusCode.' fout op '.$this->request->getHost();
//Set from and to
$this->from(config('mail.from.address'), config('mail.from.name'));
$this->to(config('mail.admin.address'));
$this->subject($subject);
//Check if it is an access denied mail. If so ommit the stack trace since that will contain the database credentials.
if(is_a($this->exception, \PDOException::class)) {
$stackTrace = 'Ommitted because of security reasons.';
}
//And return a view for the message
$data = [
'request' => $this->request,
'requestUri' => $requestUri,
'stackTrace' => $stackTrace,
'code' => $this->httpStatusCode,
'errorMessage' => $errorMessage
];
$this->view('emails.admin-error', $data);
return $this;
}
private function makeStackTraceLookNicer($stack)
{
return preg_replace('/(?<=#\d ).*:|(?<=#\d\d ).*:|(?<=#\d\d\d ).*:/m', '<b>$0</b>', $stack);
}
}