* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace CachetHQ\Cachet\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Watson\Validating\ValidatingTrait; class Subscriber extends Model { use SoftDeletes, ValidatingTrait; /** * The validation rules. * * @var string[] */ protected $rules = [ 'email' => 'required|email|unique:subscribers', ]; /** * The fillable properties. * * @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); } }