Search code examples
phpemailmodellaravel-5.3facade

Call to undefined method Illuminate\Notifications\Channels\MailChannel::route()


I am trying to send notification to a particular mail id and is using the following code in my controller:

    $product=Product::first();
    Notification::route('mail','suraj@yahoo.com')
   ->notify(new NewProducts($product));

But I get an error Call to undefined method Illuminate\Notifications\Channels\MailChannel::route() . All prerequisites are being added and I even successfully sent a mail when i used an object of my User model. I came across this process in laravel doc5.3.


Solution

  • The best way to find out where the issue is would be:


    1. Go to laravel/framework on Github


    2. Type the reported class into search in the top of the page

    enter image description here

    It fill find few results

    Among others, MailChannel class


    3. Scan the MailChannel class to find the right method

    Just looking at class, you'll quickly find send() method, that does what you want. As suggested by @Suraj



    All this work can be automated nowadays by using IDE - smart software editor. From my 5+ years experience I recommend PHPStorm, but you can use any.

    Why?

    It does all 4 steps above right in your browser. Tells you what methods are available on all classes.

    enter image description here