Skip to content
Advertisement

Can’t find my Mailable class from Route::get

I’m getting this error in Laravel while trying to get from route method. My error is:

Symfony Component Debug Exception FatalThrowableError

(E_ERROR) Class ‘NewUserWelcomeMail’ not found

My route method is:

Route::get('/email', function() {
  return new NewUserWelcomeMail();
});
 

NewUserWelcomeMail class code is:

<?php

namespace AppMail;

use IlluminateBusQueueable;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;
use IlluminateContractsQueueShouldQueue;

class NewUserWelcomeMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('emails.welcome-email');
    }
}

I tried this as this video said but don’t understand why my one is not working as all rest are working fine. Video time from 4:13:00.

Advertisement

Answer

You need to specify the namespace. Change your route code to the following:

Route::get('/email', function() {
  return new AppMailNewUserWelcomeMail();
});
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement