public static function createLocations($agentId, $cityIds) { $result = true; foreach ($cityIds as $cityId) { $userLocations = new UserAgentLocations(); $userLocations->agent_id = $agentId; $userLocations->city_id = $cityId; $result = $result && $userLocations->save(); } return $result; }