public static function increment($country, $url) { if (is_a($url, Url::className())) { $url = $url->id; } if (!is_numeric($url)) { throw new InvalidParamException('Url must be a number or object of app\\models\\Url with id'); } $countryUrl = CountryUrl::findOne(['country_name' => $country, 'id_url' => $url]); if (empty($countryUrl)) { $countryUrl = new CountryUrl(['country_name' => $country, 'id_url' => $url, 'counter' => 1]); } else { $countryUrl->counter++; } $countryUrl->save(); }