如何在Laravel中使用具有多重身份验证的验证电子邮件?

时间:2019-08-05 10:22:54

标签: laravel email-verification

我建立了一个具有两个保护的多重身份验证Laravel系统:“用户”和“客户”。 现在,我想验证新注册客户(而不是用户)的邮件。

我添加了

use Illuminate\Contracts\Auth\MustVerifyEmail;

class Customer extends Authenticatable implements MustVerifyEmail

自定义模型。

我添加了

Route::get('email/resend', 'CustomerAuth\VerificationController@resend')->name('verification.resend');
Route::get('email/verify', 'CustomerAuth\VerificationController@show')->name('verification.notice');
Route::get('email/verify/{id}', 'CustomerAuth\VerificationController@verify')->name('verification.verify');

去路线

我已经在views / auth中构建了“ verify.blade”

我已经创建了CustomerAuth \ VerificationController

现在,Laravel向新客户发送了一封验证电子邮件,但它没有对其进行验证,也没有显示任何消息。如果客户单击验证链接,Laravel会将客户发送回首页。 >

在这里app / Http / Controllers / CustomerAuth / VerificationController.php

namespace App\Http\Controllers\CustomerAuth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\VerifiesEmails;
class VerificationController extends Controller
{    
use VerifiesEmails;

protected $redirectTo = '/home';

public function __construct()
{
    $this->middleware('auth');
    $this->middleware('signed')->only('verify');
    $this->middleware('throttle:6,1')->only('verify', 'resend');
}
}

我也尝试过      $this->middleware('auth:customer');

auth.php

return [
'defaults' => [
'guard' => 'user',
'passwords' => 'users',
],
'guards' => [
'user' => [
'driver' => 'session',
'provider' => 'users',
],
'customer' => [
'driver' => 'session',
'provider' => 'customers',
],
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'customers' => [
'driver' => 'eloquent',
'model' => App\Customer::class,
],
],
'passwords' => [
'customers' => [
'provider' => 'customers',
'table' => 'customer_password_resets',
'expire' => 60,
],
'users' => [
'provider' => 'users',
'table' => 'user_password_resets',
'expire' => 60,
],  
],
];

0 个答案:

没有答案