【问题标题】:How to Extend Laravel Verification如何扩展 Laravel 验证
【发布时间】:2020-03-14 01:57:51
【问题描述】:

我正在开发一个使用 Laravel 验证的 Laravel 应用程序。

我已经设置了 Laravel 验证。

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('role')->default('family');
        $table->timestamp('email_verified_at')->nullable();
        $table->date('trialExpires')->nullable();
        $table->string('avatar')->nullable();
        $table->timestamp('sub_paid_at')->nullable();
        $table->string('session_id')->nullable();
        $table->string('password')->nullable();
        $table->rememberToken();
        $table->timestamps();

    });
}

当用户验证他的电子邮件时,我正在尝试更新trialExpires 列。

我会这样做

$user = User::find(Auth::id());
// get the current time
$current = Carbon::now();
// add 30 days to the current time
$user->trialExpires = $current->addDays(30);
$user->save();

不知道用户验证邮箱的时候如何实现这个功能。

【问题讨论】:

    标签: laravel


    【解决方案1】:

    你可以收听事件

    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        'Illuminate\Auth\Events\Verified' => [
            'App\Listeners\LogVerifiedUser',
        ],
    ]
    

    一旦通过验证(查看docs,了解如何将验证过程添加到模型等),您可以将过期值添加到列中。

    【讨论】:

    • 这是一个好的开始,但是添加一些细节,包括documentation links,关于如何编写事件监听器(或者甚至提到它是必要的)会很有帮助。
    猜你喜欢
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    • 2023-03-04
    • 2018-11-26
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 2017-03-11
    相关资源
    最近更新 更多