Laravel请求验证不适用于邮递员请求



对于以下请求,当主体参数以JSON形式发送时,它总是验证请求(就像在没有触发验证规则的情况下一样(,但当以表单数据或表单url编码发送时,会通过验证规则。这是拉拉威尔的限制吗?

namespace AppApiRequestsOrganizationUser;
use AppApiConstantsPlatformRoles;
use FrameworkHttpRequestsAPIFormRequest;
class CreateNewUserRequest extends APIFormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'bail|required|string|max:255',
'access' => 'present|array',
'access.*.access_type' => ['bail', 'sometimes', 'string'],
'access.*.id' => ['bail', 'sometimes', 'string']
];
}
}

couz当您将其作为表单数据发送时,主体结构发生了更改,请尝试添加您的请求,并查看请求的外观。

public function rules()
{
dd($this->request->all());

正确设置邮件头:

内容类型:application/json

接受:application/json

最新更新