我正在开发一个使用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();
当用户验证电子邮件时,我不知道如何实现此功能。
答案 0 :(得分:1)
您可以收听事件
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'Illuminate\Auth\Events\Verified' => [
'App\Listeners\LogVerifiedUser',
],
]
一旦完成验证(检查docs如何将验证过程添加到模型等),就可以将过期值添加到列中。