/** * The "booting" method of the model. * * @return void */ public static function boot() { parent::boot(); User::creating(function ($user) { if (!$user->email) { throw new \Exception('User model must contain a not-null email attribute'); } if (!$user->username) { $user->username = $user->email; } }); }