Inheritance: extends Illuminate\Database\Eloquent\Model
Exemple #1
0
 public static function checkWhenUsernameAvailable($username)
 {
     $user = self::whereIn('username', [str_replace(' ', '_', $username), str_replace('_', ' ', $username)])->first();
     if ($user === null) {
         $lastUsage = UsernameChangeHistory::where('username_last', $username)->orderBy('change_id', 'desc')->first();
         if ($lastUsage === null) {
             return Carbon::now();
         }
         return Carbon::parse($lastUsage->timestamp)->addMonths(6);
     }
     if ($user->group_id !== 2 || $user->user_type === 1) {
         //reserved usernames
         return Carbon::now()->addYears(10);
     }
     $playCount = array_reduce($user->statisticsAll(true), function ($result, $stats) {
         return $result + $stats->value('playcount');
     }, 0);
     return $user->user_lastvisit->addMonths(6)->addDays($playCount * 0.75);
     //bonus based on playcount
 }