ValidUrl.php 518 B

123456789101112131415161718192021
  1. <?php
  2. namespace App\Rules;
  3. use Closure;
  4. use Illuminate\Contracts\Validation\ValidationRule;
  5. class ValidUrl implements ValidationRule
  6. {
  7. /**
  8. * Run the validation rule.
  9. *
  10. * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
  11. */
  12. public function validate(string $attribute, mixed $value, Closure $fail): void
  13. {
  14. if (!str_starts_with(strtolower($value), 'https://')) {
  15. $fail('The :attribute must start with https://.');
  16. }
  17. }
  18. }