PHPackages                             atldays/laravel-url - 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. atldays/laravel-url

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

atldays/laravel-url
===================

Laravel package for URL value objects, sanitization pipelines, browser URL support, validation rules, request macros, and Laravel Data integration.

v1.0.0(1mo ago)0731MITPHPPHP ^8.2CI passing

Since Apr 16Pushed 1mo agoCompare

[ Source](https://github.com/atldays/laravel-url)[ Packagist](https://packagist.org/packages/atldays/laravel-url)[ Docs](https://github.com/atldays/laravel-url)[ RSS](/packages/atldays-laravel-url/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (10)Versions (3)Used By (1)

Laravel URL
===========

[](#laravel-url)

[![Latest Version on Packagist](https://camo.githubusercontent.com/056ccfc8a8047f61c166ebba899fa183d1ee59b21ef560d4c3b1449b6a97f267/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61746c646179732f6c61726176656c2d75726c2e7376673f6c6f676f3d7061636b6167697374267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/atldays/laravel-url)[![Total Downloads](https://camo.githubusercontent.com/8a2e80815bcc9ce23e1f6f42142625933e493b03a4fd81cf0fdd32217d52471a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61746c646179732f6c61726176656c2d75726c2e7376673f7374796c653d666f722d7468652d626164676526636f6c6f723d626c7565)](https://packagist.org/packages/atldays/laravel-url/stats)[![CI](https://camo.githubusercontent.com/8804cea0a56d5f3f1fe1f9ff060808196b33a64b3acb9295246ac886734cc4ef/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61746c646179732f6c61726176656c2d75726c2f63692e796d6c3f7374796c653d666f722d7468652d6261646765266c6162656c3d4349)](https://github.com/atldays/laravel-url/actions/workflows/ci.yml)[![License: MIT](https://camo.githubusercontent.com/7a1226d14a365d288bfe51ece915ee0c7e754a16faa51ff06436504de29b33b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666f722d7468652d6261646765)](LICENSE.md)

`atldays/laravel-url` is a Laravel package for working with URLs in a more predictable, framework-friendly way.

At its core, the package builds on top of [spatie/url](https://github.com/spatie/url), adds Laravel integration, supports browser-specific schemes, provides sanitizer pipelines for unsafe input, ships validation rules, request macros, and optional integration with `spatie/laravel-data`.

Why This Package Exists
-----------------------

[](#why-this-package-exists)

Working with URLs in real applications is usually messier than simply parsing a clean string.

Inputs may come from:

- request headers such as `Origin` and `Referer`
- user-submitted form fields
- browser-specific URLs like `chrome-extension://...`
- values that contain control characters or broken UTF-8
- DTOs and data objects that need automatic casting

This package gives you a single Laravel-oriented layer for those cases while still relying on the excellent parsing foundation provided by `spatie/url`.

Features
--------

[](#features)

- `Atldays\Url\Url` value object built on top of `spatie/url`
- support for browser-specific schemes: `chrome-extension`, `moz-extension`, `chrome`, `opera`, `edge`
- URL factory with sanitizer profiles
- configurable sanitizer pipelines
- Laravel facade for short, expressive usage
- validation rules for generic URLs and browser URLs
- request macros for extracting typed URLs from headers
- optional `spatie/laravel-data` casts and transformer
- translations for validation messages

Requirements
------------

[](#requirements)

- PHP `^8.2`
- Laravel `^11.0|^12.0|^13.0`

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

[](#installation)

Install the package:

```
composer require atldays/laravel-url
```

If you want to customize sanitizer profiles, publish the config:

```
php artisan vendor:publish --tag="url-config"
```

If you want to use `spatie/laravel-data` integration, install it separately:

```
composer require spatie/laravel-data
```

Quick Start
-----------

[](#quick-start)

### Use the facade

[](#use-the-facade)

```
use Atldays\Url\Facades\Url;

$url = Url::make('https://example.com/path?sort=desc');
$url = Url::make(' "https://example.com/path?sort=desc" ', 'header');
$url = Url::makeOrNull($request->header('origin'), 'header');
```

### Use the factory directly

[](#use-the-factory-directly)

```
use Atldays\Url\UrlFactory;

$factory = app(UrlFactory::class);

$url = $factory->make('https://example.com');
$safeUrl = $factory->makeOrNull($rawValue, 'header');
```

The URL Value Object
--------------------

[](#the-url-value-object)

The package provides `Atldays\Url\Url`, which extends Spatie's URL object and adds Laravel-oriented behavior.

### Browser-specific schemes

[](#browser-specific-schemes)

```
use Atldays\Url\Url;

$url = Url::fromString('chrome-extension://extension-id/options.html');

$url->hasBrowserScheme(); // true
```

### Detect IP hosts

[](#detect-ip-hosts)

```
$url = Url::fromString('https://127.0.0.1:8080/ping');

$url->isIpHost(); // true
```

### Get the base URL

[](#get-the-base-url)

```
$url = Url::fromString('https://example.com:8443/path?x=1');

$url->getBase(); // https://example.com:8443
```

Factory And Sanitizer Profiles
------------------------------

[](#factory-and-sanitizer-profiles)

The recommended entry point for application code is `UrlFactory` or the `Url` facade.

Before the URL object is created, the factory runs the input through a configurable sanitizer pipeline.

### Default behavior

[](#default-behavior)

When you do not pass a profile explicitly, the factory uses the configured default profile:

```
$url = Url::make($value);
```

### Explicit profile

[](#explicit-profile)

```
$url = Url::make($value, 'header');
```

### Available profiles

[](#available-profiles)

The package currently ships with two profiles:

- `default`General-purpose cleanup for regular application input
- `header`Cleanup for header values such as `Origin` and `Referer`

### Built-in sanitizers

[](#built-in-sanitizers)

- `HeaderValueSanitizer`Trims wrapping quotes and header-specific whitespace noise
- `ControlCharsSanitizer`Removes control characters before parsing
- `Utf8Sanitizer`Normalizes broken UTF-8 before the final URL object is created

### Configuration

[](#configuration)

```
use Atldays\Url\Sanitizers\ControlCharsSanitizer;
use Atldays\Url\Sanitizers\HeaderValueSanitizer;
use Atldays\Url\Sanitizers\Utf8Sanitizer;

return [
    'default_profile' => 'default',

    'profiles' => [
        'default' => [
            ControlCharsSanitizer::class,
            Utf8Sanitizer::class,
        ],

        'header' => [
            HeaderValueSanitizer::class,
            ControlCharsSanitizer::class,
            Utf8Sanitizer::class,
        ],
    ],
];
```

You can add your own sanitizer classes as long as they implement:

```
Atldays\Url\Sanitizers\UrlSanitizer
```

Validation Rules
----------------

[](#validation-rules)

The package includes Laravel validation rules for both standard URLs and browser-specific URLs.

### Generic URL rule

[](#generic-url-rule)

```
use Atldays\Url\Rules\Url;

Validator::make($data, [
    'website' => ['nullable', new Url()],
]);
```

This rule:

- supports `nullable`
- rejects non-string values
- accepts browser-specific URLs
- validates regular web URLs using Laravel-friendly behavior

### Browser URL rule

[](#browser-url-rule)

```
use Atldays\Url\Rules\BrowserUrl;

Validator::make($data, [
    'extension_url' => ['nullable', new BrowserUrl()],
]);
```

This rule only accepts browser-specific schemes such as:

- `chrome-extension://...`
- `moz-extension://...`
- `chrome://...`
- `edge://...`
- `opera://...`

Request Macros
--------------

[](#request-macros)

The service provider registers a few request macros that return typed URL objects.

### `getUrlFromHeader`

[](#geturlfromheader)

```
$url = request()->getUrlFromHeader('origin');
```

### `getOriginUrl`

[](#getoriginurl)

```
$origin = request()->getOriginUrl();
```

### `getRefererUrl`

[](#getrefererurl)

```
$referer = request()->getRefererUrl();
```

### `getFullUrl`

[](#getfullurl)

```
$current = request()->getFullUrl();
```

These macros:

- parse values through the package factory
- use the `header` profile when reading headers
- return `null` or the provided default when parsing fails
- reject header URLs with IP hosts

`spatie/laravel-data` Integration
---------------------------------

[](#spatielaravel-data-integration)

If your project uses `spatie/laravel-data`, the package provides casts and a transformer under `src/Data`.

### `UrlCast`

[](#urlcast)

Use `UrlCast` when the incoming value must already be a valid URL.

```
use Atldays\Url\Data\Casts\UrlCast;
use Atldays\Url\Data\Transformers\UrlTransformer;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Attributes\WithTransformer;
use Spatie\LaravelData\Data;

final class LinkData extends Data
{
    public function __construct(
        #[WithCast(UrlCast::class)]
        #[WithTransformer(UrlTransformer::class)]
        public \Atldays\Url\Contracts\Url|null $url,
    ) {}
}
```

### `ToUrlCast`

[](#tourlcast)

Use `ToUrlCast` when you want to coerce host-like values into full URLs.

Examples it can handle:

- `https://example.com/path`
- `example.com/path`
- `example.com`

```
use Atldays\Url\Data\Casts\ToUrlCast;

final class HostData extends Data
{
    public function __construct(
        #[WithCast(ToUrlCast::class)]
        public \Atldays\Url\Contracts\Url|null $url,
    ) {}
}
```

### `UrlTransformer`

[](#urltransformer)

`UrlTransformer` converts the URL object back to its string representation when the data object is transformed.

Contracts
---------

[](#contracts)

The package exposes a small set of contracts under `Atldays\Url\Contracts`, including:

- `Url`
- `Query`
- `Segment`
- `Urlable`

These contracts are useful when you want to type against abstractions instead of the concrete URL implementation.

Translations
------------

[](#translations)

Validation messages are provided through the package translation namespace:

```
url::validation.url
url::validation.browser_url
```

If you want to publish the package translations into your Laravel application and customize them, run:

```
php artisan vendor:publish --tag="url-translations"
```

After publishing, you can override the package translations in:

```
lang/vendor/url

```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Check formatting:

```
composer format:test
```

Auto-fix formatting:

```
composer format
```

Credits
-------

[](#credits)

- [Spatie URL](https://github.com/spatie/url) for the parsing foundation
- [Spatie Laravel Package Tools](https://github.com/spatie/laravel-package-tools)
- [Spatie Laravel Data](https://github.com/spatie/laravel-data) for optional DTO integration

License
-------

[](#license)

The MIT License. Please see [LICENSE.md](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance89

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

54d ago

### Community

Maintainers

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

---

Top Contributors

[![atldays](https://avatars.githubusercontent.com/u/130153594?v=4)](https://github.com/atldays "atldays (13 commits)")

---

Tags

browser-extensiondatalaravelphpspatieurlurllaravelValue Objectlaravel-packagelaravel-dataurlsurl validationbrowser-urlurl-sanitizerrequest-macrosspatie-url

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/atldays-laravel-url/health.svg)

```
[![Health](https://phpackages.com/badges/atldays-laravel-url/health.svg)](https://phpackages.com/packages/atldays-laravel-url)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

815320.5k3](/packages/defstudio-telegraph)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

76318.2M110](/packages/laravel-mcp)[illuminate/validation

The Illuminate Validation package.

18837.7M1.6k](/packages/illuminate-validation)[spatie/laravel-health

Monitor the health of a Laravel application

87311.3M149](/packages/spatie-laravel-health)[ralphjsmit/laravel-glide

Auto-magically generate responsive images from static image files.

4923.6k5](/packages/ralphjsmit-laravel-glide)

PHPackages © 2026

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