我正在独自学习Laravel。 进入“创建激活电子邮件”阶段时,我被激活链接卡住了。
我按照Laravel HP中的手册进行操作。电子邮件已发送到邮箱,但是当我单击激活链接时,列“ email_verified_at”未更新,并且我被重定向到登录页面,没有任何反应。
Auth::routes(['verify' => true]);
Route::get('home', 'HomeController@index')->name('home')->middleware('verified');
Route::get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify');
Route::get('login','Auth\LoginController@showLoginForm')->name('login');
Route::post('login','Auth\LoginController@checkLogin');
Route::get('register','Auth\RegisterController@create');
Route::post('register','Auth\RegisterController@store');
Route::get('logout','Auth\LoginController@logout')->name('logout');
use Notifiable;
protected $fillable = ['id','name', 'email', 'password', 'role'];
protected $hidden = ['password', 'remember_token'];
public function setPasswordAttribute($password)
{
$this->attributes['password'] = bcrypt($password);
}
protected $casts = [
'email_verified_at' => 'datetime',
];
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');
}
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
}
public function create()
{
return view('registration.create');
}
protected function store(Request $request)
{
$rules = [
'name' =>'required|unique:users,name',
'email' =>'required|email|unique:users,email',
'password' => 'required|min:8',
'role' => ['required',Rule::in(['admin', 'user'])],
];
$messages = [
'name.required' => 'Username is required!',
'email.required' => 'Email is required!',
'email.email' => 'Email is invalid!',
'password.required' => 'Password is required!',
'password.min' => 'Password must have at least 8digit!',
];
$validator = Validator::make($request->all(), $rules, $messages);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
} else {
$user = User::create([
'name' => $request['name'],
'email' => $request['email'],
'password' => bcrypt($request['password']),
'role' => $request['role'],
]);
}
$user->sendEmailVerificationNotification();
return $user;
}
{"name":"654321","email":"111111111@yahoo.com","role":"admin","updated_at":"2019-04-10 03:40:43","created_at":"2019-04-10 03:40:43","id":49}