Changeset View
Changeset View
Standalone View
Standalone View
src/app/Traits/UserAliasesTrait.php
<?php | <?php | ||||
namespace App\Traits; | namespace App\Traits; | ||||
trait UserAliasesTrait | trait UserAliasesTrait | ||||
{ | { | ||||
/** | /** | ||||
* Find whether an email address exists as an alias | |||||
* (including aliases of deleted users). | |||||
* | |||||
* @param string $email Email address | |||||
* | |||||
* @return bool True if found, False otherwise | |||||
*/ | |||||
public static function aliasExists(string $email): bool | |||||
{ | |||||
if (strpos($email, '@') === false) { | |||||
return false; | |||||
} | |||||
$email = \strtolower($email); | |||||
$count = \App\UserAlias::where('alias', $email)->count(); | |||||
return $count > 0; | |||||
} | |||||
/** | |||||
* A helper to update user aliases list. | * A helper to update user aliases list. | ||||
* | * | ||||
* Example Usage: | * Example Usage: | ||||
* | * | ||||
* ```php | * ```php | ||||
* $user = User::firstOrCreate(['email' => 'some@other.org']); | * $user = User::firstOrCreate(['email' => 'some@other.org']); | ||||
* $user->setAliases(['alias1@other.org', 'alias2@other.org']); | * $user->setAliases(['alias1@other.org', 'alias2@other.org']); | ||||
* ``` | * ``` | ||||
Show All 25 Lines |