StoreDiscussionRequest.php 947 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use App\Services\AuthService;
  5. class StoreDiscussionRequest extends FormRequest
  6. {
  7. private $user;
  8. /**
  9. * Determine if the user is authorized to make this request.
  10. *
  11. * @return bool
  12. */
  13. public function authorize()
  14. {
  15. $user = AuthService::current($this);
  16. if (!$user) {
  17. return false;
  18. }
  19. $this->user = $user;
  20. return true;
  21. }
  22. /**
  23. * Get the validation rules that apply to the request.
  24. *
  25. * @return array
  26. */
  27. public function rules(): array
  28. {
  29. return [
  30. 'res_id' => 'required|string',
  31. 'res_type' => 'required|string',
  32. ];
  33. }
  34. public function messages(): array
  35. {
  36. return [
  37. 'res_id.required' => 'res_type是必填项',
  38. 'res_type.required' => 'type是必填项',
  39. ];
  40. }
  41. }