PHPackages                             hampel/tlds - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. hampel/tlds

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

hampel/tlds
===========

Fetches the latest list of Top Level Domains from IANA, plus Laravel classes for validating TLDs

2.1.0(2y ago)13.4k↓72.9%1[1 PRs](https://github.com/hampel/tlds/pulls)MITPHPPHP &gt;=7.3

Since Oct 3Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hampel/tlds)[ Packagist](https://packagist.org/packages/hampel/tlds)[ Docs](https://github.com/hampel/tlds)[ RSS](/packages/hampel-tlds/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (5)Versions (23)Used By (0)

Top Level Domain Fetcher for Laravel
====================================

[](#top-level-domain-fetcher-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/dc457d27558a5e9092ec0df5e7bcb05cf5ffdf287a218207439dbc0733e3b9b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616d70656c2f746c64732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/tlds)[![Total Downloads](https://camo.githubusercontent.com/cf9b023b9575466f671b2f4552f5dc06b16948001a0485e1f3dde73879e75582/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616d70656c2f746c64732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/tlds)[![Open Issues](https://camo.githubusercontent.com/6826cca70003df8e04bd523936a0d3cc3bec613414c9edcc307b0baeba46b5cd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f68616d70656c2f746c64732e7376673f7374796c653d666c61742d737175617265)](https://github.com/hampel/tlds/issues)[![License](https://camo.githubusercontent.com/b9824b8101ba7205b5b295dc615ff8f12d6f944418b88549cc8c478d8473356f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68616d70656c2f746c64732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/tlds)

This package provides a mechanism for retrieving a list of the current Top Level Domains (TLDs) managed by IANA. It also provides several Laravel classes to validate domain names and TLDs.

By [Simon Hampel](mailto:simon@hampelgroup.com)

Compatibility
-------------

[](#compatibility)

- Laravel 9.x - use hampel/tlds 1.10.x
- Laravel 10.x - use hampel/tlds 2.x
- Laravel 11.x - use hampel/tlds 2.1.x

Installation
------------

[](#installation)

To install using composer, run the following command:

`composer require hampel/tlds`

If you want to change the default Tlds configuration, first publish it using the command:

```
$ php artisan vendor:publish --provider="Hampel\Tlds\TldServiceProvider"
```

The config files can then be found in `config/tlds.php`.

Configuration
-------------

[](#configuration)

Refer to the configuration file for more details about configuration options.

**tlds.cache.expiry** - sets the cache expiry time in seconds

**tlds.cache.key** - sets the key used to store the TLD data in the cache

**tlds.source** - set this to 'url' to retrieve the data from a website (eg IANA), set it to 'filesystem' to retrieve the data from a local source (you'll need to configure a Laravel filesystem 'disk' to make this work).

**tlds.url** - if source is set to 'url', enter the URL to retrieve the data from. By default this is set to the IANA source file

**tlds.disk** - if source is set to 'filesystem', enter the name of the Laravel filesystem disk you have configured in the 'filesystems.disks' configuration option

**tlds.path** - if source is set to 'filesystem', enter the path to the data file relative to the root path configured for the disk in the 'fileystems.disks' configuration option (eg. 'tlds/tlds-alpha-by-domain.txt')

Usage
-----

[](#usage)

The Tlds package provides a simple mechanism for reading a data file containing a list of Top Level Domains, one per line and returning an array of data. This data may optionally be cached for performance.

The data file can be retrieved directly from the Internet Assigned Numbers Authority (IANA) website, using Guzzle, or if you have a different source or prefer to fetch the data file yourself and then read it from a local source you can reconfigure the Tlds package to read the data file from any Laravel supported filesystem (using Flysystem).

There is also an artisan command available which can be used to fetch the latest data file to refresh the cache. This is ideal for automating the retrieval of data using a cron job or similar.

The simplest way to call the package is using the Facade:

```
// get a "fresh" copy of the TLD list
$tld_array = Tlds::fresh();

// or if you prefer to not use Facades:
$tld_array = $app->make(Hampel\Tlds\TldManager::class)->fresh();
```

This returns a "fresh" copy of the data (bypassing the cache) as an array of TLDs.

To fetch the TLD array from the cache or have it update automatically if the cached data has expired

```
// get the TLD list from the cache (or update the cache if it has expired)
$tld_array = Tlds::get();

// if you prefer to manage the cache yourself, you can do this all manually, for example:
if (Cache::has(Config::get('tlds.cache.key'))
{
    $tld_array = Cache::get(Config::get('tlds.cache.key'));
}
else
{
    Cache::put(Config::get('tlds.cache.key'), Tlds::fresh(), Config::get('tlds.cache.expiry'));
}
```

To run the artisan console command to update the cache:

```
$ php artisan tld:update
Added 725 TLDs to the TLD Cache
```

Validators
----------

[](#validators)

This package adds additional validators for Laravel v10.x and above - refer to [Laravel Documentation - Validation](http://laravel.com/docs/validation) for general usage instructions.

**Domain**

The field under validation must be a valid domain name. The Top Level Domain (TLD) is checked against a list of all acceptable TLDs, including internationalised domains in punycode notation

Example:

```
use Hampel\Tlds\Validation\Domain;

// valid values: example.com; example.au
// invalid values: example.invalid-tld

$request->validate([
    'domain' => ['required', 'string', new Domain],
]);
```

**DomainIn(\[&lt;array of TLDs&gt;\])**

The field under validation must be a valid domain with a TLD from one of the specified options

Example:

```
use Hampel\Tlds\Validation\DomainIn;

// valid values: example.com; example.net
// invalid values: example.co; example.au (not in specified list of domain TLDs)

$request->validate([
    'domain' => ['required', 'string', new DomainIn(['com', 'net')],
]);
```

**Tld**

The field under validation must end in a valid Top Level Domain (TLD). The TLD is checked against a list of all acceptable TLDs, including internationalised domains in punycode notation

If no dots are contained in the supplied value, it will be assumed to be only a TLD.

If the value contains dots, only the part after the last dot will be validated.

Example:

```
use Hampel\Tlds\Validation\Tld;

// valid values: example.com; com; net (either a domain with a valid TLD, or a string that is itself a valid TLD)
// invalid values: example.invalid-tld; something-not-a-tld

$request->validate([
    'domain' => ['required', 'string', new Tld],
]);
```

**TldIn(\[&lt;array of TLDs&gt;\])**

The field under validation must end in a TLD from one of the specified options

If no dots are contained in the supplied value, it will be assumed to be only a TLD.

If the value contains dots, only the part after the last dot will be validated.

Example:

```
use Hampel\Tlds\Validation\TldIn;

// valid values: example.com; example.net; com; net
// invalid values: example.co; org (not in specified list of domain TLDs)

$request->validate([
    'domain' => ['required', 'string', new TldIn(['com', 'net'])],
]);
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 97.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~167 days

Recently: every ~159 days

Total

22

Last Release

787d ago

Major Versions

1.6.0 → 5.7.x-dev2019-03-27

1.10.1 → 2.0.02024-05-08

PHP version history (4 changes)1.0.0PHP &gt;=5.4.0

1.3.0PHP &gt;=5.5.9

1.4.0PHP &gt;=5.5

2.0.0PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2e02745af0cfa73e5f00eb8faf965a13296351e62f4802cc76a148cdbc95dbd?d=identicon)[hampel](/maintainers/hampel)

---

Top Contributors

[![simonhampel](https://avatars.githubusercontent.com/u/443890?v=4)](https://github.com/simonhampel "simonhampel (77 commits)")[![joshfoskett](https://avatars.githubusercontent.com/u/1159106?v=4)](https://github.com/joshfoskett "joshfoskett (2 commits)")

---

Tags

domain-namesdomainnamedomainsianatldtop-level-domainslaraveldomaintldianaTop Level Domainsdomain namedomain names

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hampel-tlds/health.svg)

```
[![Health](https://phpackages.com/badges/hampel-tlds/health.svg)](https://phpackages.com/packages/hampel-tlds)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel

3893.6M1](/packages/axlon-laravel-postal-code-validation)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2462.4M7](/packages/laravel-validation-rules-credit-card)[sandermuller/laravel-fluent-validation

Fluent validation rule builders for Laravel

20518.8k4](/packages/sandermuller-laravel-fluent-validation)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
