在 Laravel 中,abort()和之间有什么区别response()->json()?
例如:
return response()->json(['message' => 'Not found'], 404);
Run Code Online (Sandbox Code Playgroud)
和:
abort(404, 'Not found');
Run Code Online (Sandbox Code Playgroud)
编辑:我认为abort()不会抛出一个异常,如果APP_DEBUG是false在.env文件中。
这是我的代码:
protected function prepareForValidation()
{
$this->replace(array_filter($this->all()));
if(!$this->all()) {
abort(422, 'You must edit something.');
}
}
Run Code Online (Sandbox Code Playgroud)
如果请求中的所有字段都为空,如果我使用它立即停止执行并返回消息(在开始验证之前)是否有问题?
laravel ×1