frostbitten/flexible-url
最新稳定版本:1.0.0
Composer 安装命令:
composer require frostbitten/flexible-url
包简介
A Laravel validation rule that accepts URLs without a scheme and normalizes them to https://
README 文档
README
A Laravel validation rule that accepts URLs with or without a scheme. When the scheme is missing, it normalizes the value to https:// automatically.
Users type google.com, not https://google.com. This rule handles that gracefully.
Installation
composer require frostbitten/flexible-url
Usage
Use it as a drop-in replacement for Laravel's url rule:
use Frostbitten\FlexibleUrl\FlexibleUrl; public function rules(): array { return [ 'website' => ['nullable', new FlexibleUrl], ]; }
When a user submits example.com, the rule:
- Prepends
https://to gethttps://example.com - Validates the normalized URL using Laravel's built-in
urlrule - Updates the validator data so
$request->validated()returns the normalized value
URLs that already include http:// or https:// are left untouched.
How normalization works
The normalized value is written back to the validator's internal data via an after callback. This means $validator->validated() (and by extension $request->validated() in Form Requests) returns the normalized URL.
This works in all contexts:
- Form Requests
- Livewire validation
- Manual
Validator::make()calls - Artisan commands
After-normalization callback
For cases where you need additional control, pass a callback:
new FlexibleUrl(function (string $attribute, string $normalizedValue) { // e.g. update a Livewire property $this->$attribute = $normalizedValue; })
The callback is only invoked when normalization actually occurs (i.e. a scheme was prepended). It is not called when the URL already has a scheme.
Requirements
- PHP 8.2+
- Laravel 11 or 12
License
MIT
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-11