Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MailChannel dependencies on markdown resolver #19320

Closed
chaoszcat opened this issue May 24, 2017 · 1 comment
Closed

MailChannel dependencies on markdown resolver #19320

chaoszcat opened this issue May 24, 2017 · 1 comment

Comments

@chaoszcat
Copy link

chaoszcat commented May 24, 2017

  • Laravel Version: 5.4.23
  • PHP Version: Not related
  • Database Driver & Version: Not related

Description:

This is about MailChannel on Notifications.

In the documentation, it does mention that to use mail channel, we should return ['mail'] in the via method. So because I have two other custom channels, I did this at first:

return [PushChannel::class, SMSChannel::class, 'mail'];

Then because of OCD, I changed it to:

return [PushChannel::class, SMSChannel::class, MailChannel::class];

And very soon, I received this error:

[2017-05-24 03:24:48] local.ERROR: ErrorException: call_user_func() expects parameter 1 to be a valid callback, no array or string given in /var/www/html/vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php:75
Stack trace:
.... not important ...

Apparently, what happened here is MailChannel (line 69) is expecting MailMessage to provide a view, if not, provide a markdownResolver, but neither of these can be fulfilled because (1) MailMessage does not need to define a view, and (2) markdownResolver is not set from ChannelManager, in line 90, because it sorts of skipped when I use MailChannel::class.

Steps To Reproduce:

  1. Create a new Notification called TestNotification.php under app/Notifications/:

    <?php
    
    namespace App\Notifications;
    
    use Illuminate\Notifications\Channels\MailChannel;
    use Illuminate\Notifications\Messages\MailMessage;
    
    class TestNotification extends \Illuminate\Notifications\Notification
    {
        public function via($notifiable)
        {
           return [MailChannel::class];
        }
    
        public function toMail($notifiable)
        {
           return (new MailMessage())->subject('Test Notification')
                                     ->line('Hello World');
        }
    }
    
  2. Use any notifiable model, and notify with this notification:

    \App\User::find(1)->notify(new \App\Notifications\TestNotification);
    
  3. This would result in an error as (1) view is not defined in MailMessage, and (2) the MailChannel was not properly initialized due to missing markdownResolver (ChannelManager does not call markdownResolver on the MailChannel.


This is definitely not a bug, but could be a pitfall for someone like me to fall into.

@themsaid
Copy link
Member

Thank you, that'll be taken care of in 5.5 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants