Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add hasVerifiedEmail scope #35217

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Illuminate/Auth/MustVerifyEmail.php
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Auth;

use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Database\Eloquent\Builder;

trait MustVerifyEmail
{
Expand Down Expand Up @@ -47,4 +48,15 @@ public function getEmailForVerification()
{
return $this->email;
}

/**
* Scope a query to only include users with verified email.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeHasVerifiedEmail(Builder $query)
{
return $query->whereNotNull('email_verified_at');
}
}
10 changes: 10 additions & 0 deletions src/Illuminate/Contracts/Auth/MustVerifyEmail.php
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Contracts\Auth;

use Illuminate\Database\Eloquent\Builder;

interface MustVerifyEmail
{
/**
Expand Down Expand Up @@ -31,4 +33,12 @@ public function sendEmailVerificationNotification();
* @return string
*/
public function getEmailForVerification();

/**
* Scope a query to only include users with verified email.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeHasVerifiedEmail(Builder $query);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change for any class that implements this interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't think this needs to be added to the interface since this is leaking Eloquent into the auth component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was hesitating about that. I remove that from the interface.

}