Php 拉威尔验证问题

Php 拉威尔验证问题,php,laravel,crud,dingo-api,Php,Laravel,Crud,Dingo Api,当验证程序执行规则时,我遇到一个问题 return [ 'features' => 'required|array', 'features.*' => 'required|string', 'link' => 'required|url', 'image' => 'nullable|file|image|mimes:jpeg,png,gif,webp|max:2048',

当验证程序执行规则时,我遇到一个问题

return [
            'features' => 'required|array',
            'features.*' => 'required|string',
            'link' => 'required|url',
            'image' => 'nullable|file|image|mimes:jpeg,png,gif,webp|max:2048',
        ];
返回一个错误,即即使字段存在,也需要字段。 我不明白是什么引起了这个问题。我使用相同的验证进行存储,它工作得非常好

这是我的控制器代码

public function update(UpdateSite $request, Site $site)
    {
        $validatedData = $request->validated();



        if ($validatedData['image']) {
            Storage::delete($site->path);

            $imagePath = $validatedData['image']->store('thumbnails');
            $interventedImage = Image::make(Storage::url($imagePath));
            $interventedImage->resize(500, null, function ($constraint) {
                $constraint->aspectRatio();
            });
            $interventedImage->save('storage/'.$imagePath);

            $site->update([
                'path' => $imagePath,
            ]);
        }

        $site->update([
            'site_link' => $validatedData['link'],
        ]);

        $site->features()->delete();

        if ($validatedData['features']) {
            foreach ($validatedData['features'] as $feature) {
                $site->features()->save(new SiteFeature(["feature" => $feature]));
            }
        }

        return $this->response->item($site, new SiteTransformer);
    }
更新#1 我的路线
$api->put('sites/{id}','SiteController@update')->其中(['id'=>'\d+')

我看到api方法是
PUT
,但是您使用Postman by
表单数据来请求。尝试使用
x-www-form-urlencoded
请求api

这是关于我的考试。对不起我的英语


问题在于PHP无法处理
PUT
补丁
请求中的
多部分/表单数据
。非常奇怪的是,这个问题仍然存在,因为从2014年左右开始,互联网上就出现了一些话题

溶解 文档中有一个解决方案

因此,要更新记录,我只需要使用方法
post
而不是
put
/
patch
,并发送一个输入字段
\u method=put


我自己刚试过,调用了
put
路由。

如果功能是数组,那么第二行是正确的,但是如果以字符串形式传递功能,那么第二行应该被删除,这条规则说验证您有两个名为功能的参数,其中一个是字符串,另一个也是数组,并且是必需的

'features' => 'required|array',
'features.*' => 'required|string',

使用json请求进行测试,以查看请求或validation@Hussein刚刚做了一个
返回变量转储($request->all())
,它看起来是空的。我不明白数据在哪里丢失。你确定这个字段名
功能[0]
?@Hussein yep。尽管如此,根据错误消息
链接
也是空的。您可以包含验证和定义规则的完整代码吗?