Rule.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Illuminate\Validation;
  3. use Illuminate\Support\Collection;
  4. use Illuminate\Support\Traits\Macroable;
  5. class Rule
  6. {
  7. use Macroable;
  8. /**
  9. * Get a dimensions constraint builder instance.
  10. *
  11. * @param array $constraints
  12. * @return \Illuminate\Validation\Rules\Dimensions
  13. */
  14. public static function dimensions(array $constraints = [])
  15. {
  16. return new Rules\Dimensions($constraints);
  17. }
  18. /**
  19. * Get a exists constraint builder instance.
  20. *
  21. * @param string $table
  22. * @param string $column
  23. * @return \Illuminate\Validation\Rules\Exists
  24. */
  25. public static function exists($table, $column = 'NULL')
  26. {
  27. return new Rules\Exists($table, $column);
  28. }
  29. /**
  30. * Get an in constraint builder instance.
  31. *
  32. * @param array|string|\Illuminate\Support\Collection $values
  33. * @return \Illuminate\Validation\Rules\In
  34. */
  35. public static function in($values)
  36. {
  37. if ($values instanceof Collection) {
  38. $values = $values->toArray();
  39. }
  40. return new Rules\In(is_array($values) ? $values : func_get_args());
  41. }
  42. /**
  43. * Get a not_in constraint builder instance.
  44. *
  45. * @param array|string|\Illuminate\Support\Collection $values
  46. * @return \Illuminate\Validation\Rules\NotIn
  47. */
  48. public static function notIn($values)
  49. {
  50. if ($values instanceof Collection) {
  51. $values = $values->toArray();
  52. }
  53. return new Rules\NotIn(is_array($values) ? $values : func_get_args());
  54. }
  55. /**
  56. * Get a unique constraint builder instance.
  57. *
  58. * @param string $table
  59. * @param string $column
  60. * @return \Illuminate\Validation\Rules\Unique
  61. */
  62. public static function unique($table, $column = 'NULL')
  63. {
  64. return new Rules\Unique($table, $column);
  65. }
  66. }