我通过互联网搜索了这个问题,我按照说明(我看到的每个网站)但我遇到了这个错误的问题“Class'App \ Http \ Controllers \ Auth \ Registered'not found”。我的控制器中是否缺少代码?我该如何解决这种错误?
我的控制器
<?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');
}
}
答案 0 :(得分:15)
使用Illuminate \ Auth \ Events \ Registered;
答案 1 :(得分:0)
解决方案(将名称空间导入Registercontroller顶部,如下所示) 使用Illuminate \ Auth \ Events \ Registered;