TWLimited.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Rules;
  3. use Illuminate\Contracts\Validation\Rule;
  4. use Illuminate\Contracts\Validation\DataAwareRule;
  5. class TWLimited implements Rule, DataAwareRule
  6. {
  7. protected $data = [];
  8. /**
  9. * Create a new rule instance.
  10. *
  11. * @return void
  12. */
  13. public function __construct()
  14. {
  15. //
  16. }
  17. /**
  18. * Determine if the validation rule passes.
  19. *
  20. * @param string $attribute
  21. * @param mixed $value
  22. * @return bool
  23. */
  24. public function passes($attribute, $value)
  25. {
  26. //
  27. if (substr($value, 0, 2)=='TW') {
  28. if (is_null($this->data['registeredSession'])) {
  29. return false;
  30. }
  31. if (is_null($this->data['lunchOptions'])) {
  32. return false;
  33. }
  34. }
  35. return true;
  36. }
  37. /**
  38. * Set the data under validation.
  39. *
  40. * @param array $data
  41. * @return $this
  42. */
  43. public function setData($data)
  44. {
  45. $this->data = $data;
  46. return $this;
  47. }
  48. /**
  49. * Get the validation error message.
  50. *
  51. * @return string
  52. */
  53. public function message()
  54. {
  55. return 'The validation error message.';
  56. }
  57. }