【发布时间】:2018-01-22 12:23:45
【问题描述】:
我的代码来验证这样的数据:
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'
]);
}
echo '<pre>';print_r($request->all());echo '</pre>';die(); 的结果如下:
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
)
data_cache是json数据
在视图刀片上,我添加了这个来显示消息验证:
@if ($errors->has('data_cache'))
<span class="help-block">
<strong>{{ $errors->first('data_cache') }}</strong>
</span>
@endif
如果代码执行,则没有显示消息验证
看来验证json数据还是错的
我怎样才能正确地做到这一点?
【问题讨论】:
标签: php json laravel validation laravel-5.3