You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On-Demand Notifications route not respected, seems is overwritten by the via notification class method
Steps To Reproduce:
run php artisan make:notification Test
set via array to database and mail
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class Test extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail', 'database'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
test with php artisan (with mail driver log) php artisan tinker \Illuminate\Support\Facades\Notification::route('mail', ['[email protected]', '[email protected]'])->notify(new \App\Notifications\Test);
check errors -> attempt to create data to db
another try with empty via array
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [];
}
check result log -> no message sent
Example of my current workaround:
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ($notifiable instanceof \Illuminate\Notifications\AnonymousNotifiable) ?
array_keys($notifiable->routes) : ['database', 'mail'];
}
Do you have any suggestions? am I wrong?
:) Thanks for the support!
The text was updated successfully, but these errors were encountered:
Hey @illambo. I tried that scenario and also get the error of the database channel. In general I think it would make sense for us to prevent using the database channel for anonymous notifiables. I'll try to whip up a pr for this. Thanks for reporting.
Description:
On-Demand Notifications route not respected, seems is overwritten by the via notification class method
Steps To Reproduce:
php artisan make:notification Test
test with php artisan (with mail driver log)
php artisan tinker
\Illuminate\Support\Facades\Notification::route('mail', ['[email protected]', '[email protected]'])->notify(new \App\Notifications\Test);
check errors -> attempt to create data to db
another try with empty via array
Example of my current workaround:
Do you have any suggestions? am I wrong?
:) Thanks for the support!
The text was updated successfully, but these errors were encountered: