找不到类“App\Http\Controllers\Auth\Registered”

Posted

技术标签:

【中文标题】找不到类“App\\Http\\Controllers\\Auth\\Registered”【英文标题】:Class 'App\Http\Controllers\Auth\Registered' not found找不到类“App\Http\Controllers\Auth\Registered” 【发布时间】:2017-04-11 17:15:51 【问题描述】:

我在互联网上搜索了有关此问题的信息,并按照说明(我看到的每个网站)进行操作,但我遇到了此错误“找不到类 'App\Http\Controllers\Auth\Registered'”的问题。我的控制器中是否缺少代码?我该如何解决这种错误?

我的控制器

<?php

namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Requests;
class RegisterController extends Controller

    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    
        $this->middleware('guest');
    

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    
        return Validator::make($data, [
            'first_name' => 'required|max:255',
            'middle_name' => 'required|max:255',
            'last_name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
        ]);
    

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    
        return User::create([

            'first_name' => $data['first_name'],
            'middle_name' => $data['middle_name'],
            'last_name' => $data['last_name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    
     public function register(Request $request)
    
        $this->validator($request->all())->validate();

        event(new Registered($user = $this->create($request->all())));

        Mail::to($ser->email)->send(new ConfirmationEmail($user));
        return back()->with('status','Please confirm your email address');
    


【问题讨论】:

你的控制器的文件名是什么?注册方法的路径?您的错误表明您在某处使用了Registered 而不是RegisterController 我做了 make:auth 命令.. 您没有导入Registered 事件。添加use Illuminate\Auth\Events\Registered;,它应该可以工作。 Source - 我的错,我没在里面看到。 我已经导入了注册但我有另一个错误大声笑。错误是 Class 'App\Http\Controllers\Auth\Mail' not found 添加use Mail; 【参考方案1】:

使用 Illuminate\Auth\Events\Registered;

【讨论】:

【参考方案2】:

解决方案(在 Registercontroller 顶部导入命名空间,如下所示) 使用 Illuminate\Auth\Events\Registered;

【讨论】:

以上是关于找不到类“App\Http\Controllers\Auth\Registered”的主要内容,如果未能解决你的问题,请参考以下文章

找不到类“App\Http\Controllers\Auth\Registered”

FPDF - 找不到类“App\Http\Controllers\FPDF”

在 Laravel 中找不到类“App\Http\Controllers\Response”错误

在 Laravel 中找不到类“App\Http\Controllers\Excel”

流明:全新安装时找不到 App\Http\Controllers\Controller 类

在 Laravel 5 中找不到类“App\Http\Controllers\Artisan”