Skip to content

Instantly share code, notes, and snippets.

@yusidabcs
Created May 17, 2018 08:02
Show Gist options
  • Save yusidabcs/2e31c2d2d459fb533964d87bc22044b6 to your computer and use it in GitHub Desktop.
Save yusidabcs/2e31c2d2d459fb533964d87bc22044b6 to your computer and use it in GitHub Desktop.
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\SlackMessage;
use Exception;
class ErrorNotification extends Notification
{
use Queueable;
public $exception;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Exception $exception)
{
$this->exception = $exception;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['slack'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toSlack($notifiable)
{
return (new SlackMessage)
->from('laravel', ':ghost:')
->to('#general')
->content('ERROR: '.$this->exception->getMessage() . '(' . $this->exception->getCode() . ') => ' . $this->exception->getFile() . ':' . $this->exception->getline() );
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment