Skip to content
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

[11.x] Add fluent URL validation class rule #54519

Open
wants to merge 12 commits into
base: 11.x
Choose a base branch
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
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.

1 participant