* @date: 2021-04-18 12:25 */ namespace Modules\Api\Requests; use App\Exceptions\ApiException; use Illuminate\Foundation\Http\FormRequest; use \Illuminate\Contracts\Validation\Validator; class BaseRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { //默认放行auth校验 return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ // ]; } /** * 重定义校验失败 * @param Validator $validator * @throws ApiException */ protected function failedValidation(Validator $validator) { throw new ApiException($validator->messages()->first(), 500); } /** * 重定义认证失败 * @throws ApiException */ protected function failedAuthorization() { throw new ApiException('认证错误', 403); } }