StoreDiscussionRequest.php 1.0 KB

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