Closed patoui closed 6 years ago
@patoui I needed this in my current project and just added it to my fluent validation rule builder. You can specify multiple schemes.
Rule::urlWithScheme(['https', 'fb'])
You probably don't want to pull that package in (or maybe you do!) just for that, but you can dig into the source and see the regex I'm using and implement that in your own app if you wanted.
@timacdonald That's pretty neat! Thanks for pinging me, definitely good to see how someone else implemented it.
The idea is to allow the
url
validation rule to accept additional protocols (url:fb,twitter,yel
) for the purpose of deep linking (or whatever your use case may be). http://mobiledeeplinking.org/#1.3-examplesLaravel 5.3 https://github.com/laravel/framework/blob/5.3/src/Illuminate/Validation/Validator.php#L1580
Laravel 5.4 https://github.com/laravel/framework/blob/5.4/src/Illuminate/Validation/Concerns/ValidatesAttributes.php#L1293
So then you could write validation like this:
Validator::make(['myurl' => 'fb://test.com'],['myurl' => 'url:fb'])->passes(); // true
This is also backwards compatible as you can pass no arguments:
Validator::make(['myurl' => 'fb://test.com'],['myurl' => 'url'])->passes(); // false