diff --git a/app/Models/User.php b/app/Models/User.php index 5ff54f8..9b64c45 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -35,6 +35,23 @@ public function setPasswordAttribute($password) $this->attributes['password'] = bcrypt($password); } + public function setEmailAttribute($email) + { + // Deconstruct + $parts = explode('@', $email); + + // Find '+' + $firstPart = $parts[0]; + $plusIndex = strpos($firstPart, '+'); + + // Truncate '+' and everything after it in the username + if ($plusIndex) + $firstPart = substr($firstPart, 0, $plusIndex); + + // return (new) username@domain + $this->attributes['email'] = $firstPart . '@' . (isset($parts[1]) ? $parts[1] : null); + } + public function posts() { return $this->hasMany(Post::class);