Handle subscribers

This commit is contained in:
Joseph Cohen
2015-05-24 16:33:03 -05:00
parent 254c578ca2
commit 55dcf3a277
48 changed files with 1214 additions and 35 deletions

View File

@@ -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);
}
}