laravel用json格式提交数据,验证层怎么写

2025-04-27 04:41:20
推荐回答(1个)
回答1:

由于提交上来数据是JSON,无法用框架本身的validate()方法,比如:
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);

// The blog post is valid, store in database...
}