0
我的代碼來驗證數據是這樣的:如何驗證laravel中的json數據?
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] => [email protected]
[password] => 87654321
)
的data_cache是JSON數據
在視圖葉片,我添加此顯示消息驗證:
@if ($errors->has('data_cache'))
<span class="help-block">
<strong>{{ $errors->first('data_cache') }}</strong>
</span>
@endif
如果代碼執行,也沒有顯示消息驗證
似乎驗證JSON數據仍然是錯誤的
我如何做是正確的?