CheckHexUid.php 976 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Rules;
  3. use Illuminate\Contracts\Validation\Rule;
  4. use Vinkla\Hashids\Facades\Hashids;
  5. /**
  6. * 检查用户UID是否正确 hash
  7. *
  8. * @author 刘相欣
  9. *
  10. * */
  11. class CheckHexUid implements Rule
  12. {
  13. /**
  14. * Create a new rule instance.
  15. *
  16. * @return void
  17. */
  18. public function __construct()
  19. {
  20. //
  21. }
  22. /**
  23. * Determine if the validation rule passes.
  24. *
  25. * @param string $attribute
  26. * @param mixed $value
  27. * @return bool
  28. */
  29. public function passes($attribute, $value)
  30. {
  31. // 解码
  32. $friendUid = Hashids::decodeHex(request('friend_uid',''));
  33. // 错误提示
  34. if( $friendUid > 0 ) return true;
  35. // 返回正确
  36. return false;
  37. }
  38. /**
  39. * Get the validation error message.
  40. *
  41. * @return string
  42. */
  43. public function message()
  44. {
  45. return trans('validation.check_hex_uid');
  46. }
  47. }