So I am setting up a exception handler that send a Slack notification every time an exception happens in the application, I have also setup this when a Complaint(Model) is created and that work fine. But in my Exception/Handle.php I have this setup.
Notification::route('slack', env('LOG_SLACK_WEBHOOK_URL'))->notify(new ExceptionCreated($exception));
The webhook does exist and it does work. And while dd() every possible step I know that it hits the ExceptionCreated in Notifications. So there I have this code.
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\SlackMessage;
use Carbon\Carbon;
use Throwable;
use Auth;
use Illuminate\Support\Facades\Request;
class ExceptionCreated extends Notification
{
use Queueable;
/**
* @var Throwable
*/
public $exception;
/**
* Create a new notification instance.
*
* @param \Throwable $exception
* @return void
*/
public function __construct(Throwable $exception)
{
$this->exception = $exception;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['slack'];
}
/**
* Get the slack representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\SlackMessage
*/
public function toSlack($notifiable)
{
dd($this->exception);
//and a lot of code here but that doesn't matter
}
Now when I dump inside the constructor I can see the exception is being passed correctly, but it never fires the toSlack function and I have no idea why, I have cleared cache, dump autoload and nothing seems to be working, as I said I have this exact code for my Complaints and that works fine. So any suggestions are much appreciated.