8000 [11.x] Add fluent URL validation class rule by shaedrich · Pull Request #54519 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[11.x] A 8000 dd fluent URL validation class rule #54519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from

Conversation

shaedrich
Copy link
Contributor

Similar to #54488, #53465, #54425, and #54517

Based on #54488 (comment)

Examples

Simplest case: Without constraints

use Illuminate\Validation\Rule;

public function rules()
{
    return [
        'foo' => [
            'required',
            Rule::url(), // results in 'url'
        ],
    ];
}

Active URL

use Illuminate\Validation\Rule;

public function rules()
{
    return [
        'foo' => [
            'required',
            Rule::url()->active(), // results in 'active_url'
        ],
    ];
}

With protocols

use Illuminate\Validation\Rule;

public function rules()
{
    return [
        'foo' => [
            'required',
            Rule::url('http', 'https'), // results in 'url:http,https'
            // or: Rule::url(['http', 'https'])
            // or: Rule::url(collect(['http', 'https']))
            // or: Rule::url()->protocols('http', 'https')
        ],
    ];
}

Modify protocols

use Illuminate\Validation\Rule;

public function rules()
{
    $rule = Rule::url('http', 'https');
    $rule->protocol('ftp');
    return [
        'foo' => [
            'required',
            $rule, // results in 'url:http,https,ftp'
        ],
    ];
}

@shaedrich shaedrich marked this pull request as draft February 8, 2025 14:49
@shaedrich shaedrich marked this pull request as ready for review February 8, 2025 15:57
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0