You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
707 B

  1. <?php
  2. namespace App\Rules;
  3. use Illuminate\Contracts\Validation\Rule;
  4. class MaxBound implements Rule
  5. {
  6. /**
  7. * Create a new rule instance.
  8. *
  9. * @return void
  10. */
  11. public function __construct()
  12. {
  13. //
  14. }
  15. /**
  16. * Determine if the validation rule passes.
  17. *
  18. * @param string $attribute
  19. * @param mixed $value
  20. * @return bool
  21. */
  22. public function passes($attribute, $value)
  23. {
  24. return sizeof(explode(',', trim($value, ','))) <= $this->bound;
  25. }
  26. /**
  27. * Get the validation error message.
  28. *
  29. * @return string
  30. */
  31. public function message()
  32. {
  33. return 'The :attribute is out of bound.';
  34. }
  35. }