Php 如何在laravel中验证json数据?

Php 如何在laravel中验证json数据?,php,json,laravel,validation,laravel-5.3,Php,Json,Laravel,Validation,Laravel 5.3,我的验证数据的代码如下: public function register(Request $request) { //echo '<pre>';print_r($request->all());echo '</pre>';die(); $this->validate($request, [ 'email'=>'required', 'password'=>'required', 'd

我的验证数据的代码如下:

public function register(Request $request)
{
    //echo '<pre>';print_r($request->all());echo '</pre>';die();
    $this->validate($request, [
        'email'=>'required',
        'password'=>'required',
        'data_cache.dataCache.id'=>'required|numeric'
        'data_cache.dataCache.quantity'=>'required|numeric'
    ]);
}
数据缓存是json数据

在视图刀片上,我添加了以下内容以显示消息验证:

@if($errors->has('data\u cache'))
{{$errors->first('data_cache')}
@恩迪夫
如果执行了代码,则没有显示消息验证

验证json数据似乎仍然错误

我如何才能正确地执行此操作?

您可以尝试使用

然后继续使用$validate方法

有一个字段用于检查验证中的数据字段是否为有效的json字符串,但这不是您需要的

Array
(
    [data_cache] => {"dataCache":{"id":112,"quantity":1,"information":"stamford bridge","request_date":"15-08-2017 02:30:00"},"expired":"2017-08-14T16:30:26.272Z"}
    [email] => chelsea@gmail.com
    [password] => 87654321
)
@if ($errors->has('data_cache'))
    <span class="help-block">
        <strong>{{ $errors->first('data_cache') }}</strong>
    </span>
@endif
$dataCache = json_decode($request->data_cache);

$request->merge(['id' => $dataCache.dataCache.id, 'quantity' => $dataCache.dataCache.quantity]);