laravel 仅获取已验证电子邮件的用户列表
laravel get list of users only email verified
当我尝试从 User:all()
获取用户列表时,它向我显示了同样未验证电子邮件的用户。
所以为了避免上面的情况,我写了下面的代码。
$users = User::with('selfie')->whereNotNull('email_verified_at')->orderBy('created_at', 'desc')->get();
如果有其他更短的方式,请告诉我。
希望有用
$users = User::whereNOTNULL('email_verified_at')->get();
你得到所有列表
我们可以定义作用域https://laravel.com/docs/8.x/eloquent#local-scopes
在用户模型中
public function scopeVerified($query)
{
return $query->whereNotNull('email_verified_at');
}
我们的查询看起来像
$users = User::with('selfie')
->verified()
->orderBy('created_at', 'desc')
->get();
当我尝试从 User:all()
获取用户列表时,它向我显示了同样未验证电子邮件的用户。
所以为了避免上面的情况,我写了下面的代码。
$users = User::with('selfie')->whereNotNull('email_verified_at')->orderBy('created_at', 'desc')->get();
如果有其他更短的方式,请告诉我。
希望有用
$users = User::whereNOTNULL('email_verified_at')->get();
你得到所有列表
我们可以定义作用域https://laravel.com/docs/8.x/eloquent#local-scopes
在用户模型中
public function scopeVerified($query)
{
return $query->whereNotNull('email_verified_at');
}
我们的查询看起来像
$users = User::with('selfie')
->verified()
->orderBy('created_at', 'desc')
->get();