Reputation: 2148
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 App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
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.
Upvotes: 1
Views: 332
Reputation: 21
If you're using laravel 7+ You can try changing your web route to:
Route::get('/email', function () {
return new \App\Mail\NewUserWelcomeMail();});
then your user model like so:
Mail::to($user->email)->send(new \App\Mail\NewUserWelcomeMail());
Upvotes: 0
Reputation: 3040
You need to specify the namespace. Change your route code to the following:
Route::get('/email', function() {
return new \App\Mail\NewUserWelcomeMail();
});
Upvotes: 3