我希望能够在用户验证电子邮件后才能调用如下所示的引导方法。
protected static function boot()
{
parent::boot();
static::created(function ($project) {
// create row in another table
});
}
我想插入一个新的行到另一个表只有在用户已经验证了电子邮件。那么有没有什么方法可以实现这个呢?
您想要从Auth helper访问User,从而更新您的其他模型。请注意,Auth需要在具有授权的Http上下文中使用,而不能在命令和作业中使用。
static::created(function ($project) {
$user = Auth::user();
if ($user && $user->email_verified) {
AnotherModel::create([
// your fields
]);
}
});