frostbitten/flexible-url 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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:

  1. Prepends https:// to get https://example.com
  2. Validates the normalized URL using Laravel's built-in url rule
  3. 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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固