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

Viewed 21512

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');
         }
    }
}
1 Answers

Change this dependency:

use Mail;

// ...

to this one:

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 notify your user:

Mail::to($user)->send(new MailNotify($user));
Related