Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'App\Http\Controllers\Mail' not found

Tags:

php

laravel

I get this error in the controller. I've already added a use Mail statement before the class declaration but still doesn't work.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Redirect,Response,DB,Config;
use Mail;
class EmailController extends Controller
{
    public function sendEmail()
    {
      $user = auth()->user();
      Mail::to($user)->send(new MailNotify($user));

      if (Mail::failures()) {
           return response()->Fail('error');
      }else{
           return response()->success('Successfully send in your mail');
         }
    }
}
like image 662
perfu Avatar asked Oct 24 '19 17:10

perfu


1 Answers

Try changing this:

use Mail;

// ...

to this:

use Illuminate\Support\Facades\Mail;

// ...

Also, add this to properly import the other class:

use App\Mail\MailNotify;

Just then you'll be able to do:

Mail::to($user)->send(new MailNotify($user));
like image 80
Kenny Horna Avatar answered Oct 04 '22 03:10

Kenny Horna