Laravel MustVerifyEmail没有发送电子邮件

希思·斯凯

我目前正在使用Laravel 5.7进行项目。当我MustVerifyEmailUser模型中实现该类时,该应用程序不会按预期方式发送电子邮件。情况是:

1)我在这里遵循了Laravel文档:https ://laravel.com/docs/5.7/verification

2)我使用https://mailtrap.io来测试功能,但是没有收到来自应用程序的任何验证电子邮件。

3)我尝试使用Auth::routes()而不是Auth::routes(['verify' => true])并期望出现错误,但是没有发生错误,该应用程序在用户注册后将我重定向到主页。

这是我的User模型:

<?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 = [
        'first_name', 'last_name', 'email', 'password', 'phone_number', 'username', 'role'
    ];

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

    public function freelancer()
    {
        return $this->hasOne('App\Freelancer', 'freelancer_id', 'id');
    }

    public function employer()
    {
        return $this->hasOne('App\Employer', 'employer_id', 'id');
    }
}

这是我的create()职能RegisterController.php

protected function create(array $data)
{
    if ($data['role'] == 'freelancer') {
        $user = User::create([
            'first_name' => $data['first_name'],
            'last_name' => $data['last_name'],
            'email' => $data['email'],
            'phone_number' => $data['phone_number'],
            'username' => $data['username'],
            'password' => Hash::make($data['password']),
            'role' => $data['role'],
        ])->freelancer()->create([
            'overview_description' => '',
        ]);
    } else {
        $user = User::create([
            'first_name' => $data['first_name'],
            'last_name' => $data['last_name'],
            'email' => $data['email'],
            'phone_number' => $data['phone_number'],
            'username' => $data['username'],
            'password' => Hash::make($data['password']),
            'role' => $data['role'],
        ])->employer()->create([
            'overview_description' => '',
            'number_of_employees' => 0,
        ]);
    }

    return $user;
}

FreelancerEmployer模特:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Freelancer extends Model
{
    protected $table = 'freelancer';

    public $timestamps = false;

    protected $fillable = [
      'overview_description'
    ];
}

-

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Employer extends Model
{
    protected $table = 'employer';

    public $timestamps = false;

    protected $fillable = [
      'overview_description', 'number_of_employees'
    ];
}

我认为中存在问题RegisterController,但我不确定它在哪里。有逻辑错误吗?

希思·斯凯

createRegisterController.php按如下所示更新功能后,问题解决了

  protected function create(array $data)
  {
     $user = User::create([
    'first_name' => $data['first_name'],
    'last_name' => $data['last_name'],
    'email' => $data['email'],
    'phone_number' => $data['phone_number'],
    'username' => $data['username'],
    'password' => Hash::make($data['password']),
    'role' => $data['role'],
    ]);

    return $user;
  }

至于FreelancerEmployer实例的创建过程,我将其放置在电子邮件验证之后。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章