0

对于以下请求,当正文参数作为 JSON 发送时,它总是验证请求(因为没有触发验证规则),但是当以 form-data 或 form-urlencoded 发送时,它会通过验证规则。这是 Laravel 的限制吗?

namespace App\Api\Requests\OrganizationUser;

use App\Api\Constants\PlatformRoles;
use Framework\Http\Requests\APIFormRequest;

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']
        ];
    }
}
4

1 回答 1

2

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

public function rules()
{
   dd($this->request->all());
于 2021-01-07T15:24:10.867 回答