Laravel电子邮件验证链接不起作用?

时间:2020-05-29 14:33:42

标签: php laravel verification email-verification

我已经为Laravel APP设置了电子邮件验证,但是当我注册为用户并访问mailtrap.io时,当我单击“验证电子邮件地址”按钮时,我得到403。此操作是未经授权的,但是如果我单击重新发送验证邮件,然后单击可以正常使用的按钮。

这是我的网络路线:

await Promise.resolve()

在我的用户模型中,我已经实现了MustVerifyEmail

Auth::routes(['verify' => true]);
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/', 'HomeController@index')->name('home');

Route::resource('challenge', 'ChallengesController');
Route::post('/challenge/join/{id}', 'ChallengesController@joinChallenge')->name('challenge.join');
Route::delete('/challenge/finish/{id}', 'ChallengesController@finishChallenge')->name('challenge.finish');

更新 这是我的HomeController:

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'user_id', 'name', 'username', 'email', 'password', 
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    protected $primaryKey = 'user_id';
    protected $keyType = 'string';

}

RegisterController:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware(['verified', 'auth']);
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        $user_id = auth()->id();
        $user = User::find($user_id);

        return view('home')
            ->with('challenges', $user->challenges)
            ->with('userChallenges', $user->userChallenges);
    }
}

1 个答案:

答案 0 :(得分:1)

确保您在身份验证中间件中没有身份验证路径

players.name