Handle subscribers
This commit is contained in:
@@ -18,6 +18,8 @@ use Watson\Validating\ValidatingTrait;
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $email
|
||||
* @property string $verify_code
|
||||
* @property \Carbon\Carbon $verified_at
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property \Carbon\Carbon $deleted_at
|
||||
@@ -32,7 +34,7 @@ class Subscriber extends Model
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'email' => 'required|email',
|
||||
'email' => 'required|email|unique:subscribers',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -41,4 +43,47 @@ class Subscriber extends Model
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = ['email'];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = ['deleted_at', 'verified_at'];
|
||||
|
||||
/**
|
||||
* Overrides the models boot method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::creating(function ($user) {
|
||||
if (!$user->verify_code) {
|
||||
$user->verify_code = self::generateVerifyCode();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the subscriber is verified.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function verified()
|
||||
{
|
||||
return !is_null($this->verified_at);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an new verify code.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generateVerifyCode()
|
||||
{
|
||||
return str_random(42);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user