我试图从我的Laravel 5.1应用程序抛出一个错误到我的前端Angular应用程序。抛出的错误不返回实际的状态消息,我需要:
if (Hash::check($updated_profile['current_password'], $user->password)) {
$user->password = Hash::make($updated_profile['new_password']);
return $user;
} else {
abort(500, 'Passwords do not match');
}
我也试过throw new 'Exception('Passwords do not match');
对于这两个,我在前端得到一个错误,但它缺少状态消息:
Object
data: null
headers:(name)
status: 0
statusText:""
__proto__: Object
它是在App class
中定义的,所以如果你想用它来中止当前的请求
首先在控制器顶部定义它
use App;
那么你可以像这样使用这个函数
App::abort(404,'The url not found');
使用response()辅助方法代替abort()。语法如下:
return response("Passwords do not match", 500);