dimanche 29 novembre 2020

Catch all exceptions and send them by e-mail - Laravel 7

I'm in

My dd() seems working, and I got

Illuminate\Database\QueryException {#521 ▼
  #sql: "select `color_code`, `name` from `skills` order by `created_at` desc"
  #bindings: []
  #message: "SQLSTATE[HY000] [2002] Connection refused (SQL: select `color_code`, `name` from `skills` order by `created_at` desc)"
  #code: 2002
  #file: "/Users/bheng/Sites/bheng2020/vendor/laravel/framework/src/Illuminate/Database/Connection.php"
  #line: 671
  -previous: Doctrine\DBAL\Driver\PDO\Exception {#526 ▶}
  +errorInfo: null
  trace: {▶}
}

I'm trying to mail this message to myself

SQLSTATE[HY000] [2002] Connection refused (SQL: select color_code, name from skills order by created_at desc)

Then, I tried to do this

public function report(Throwable $exception)
{

    // dd($exception);

    if(isset($exception)){
        $message = $exception->message;
        $mail = Mail::send('layouts.share.emails.log', array('message' => $message) , function ($message) use ($message) {
            $message->from(env('MAIL_FROM') , 'Server 27');

            if(env('APP_ENV') == 'local'){
                $message->to($email , 'Server 27')->subject('ERROR - 🟱');
            } else {
                $message->to($email , 'Server 27')->subject('ERROR');
            }
        });
    }

    parent::report($exception);
}

I was hoping to email all exceptions to my email but see nothing.

Kept getting this :

enter image description here



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2KMIRuJ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire