如何在 laravel 响应中发送错误?
How to send error in laravel response?
我正在编写更改密码的代码。我的代码如下:
public function changePassword(ChangePasswordRequest $request)
{
$credentials = ['email'=>Auth::user()->email, 'password'=>$request['old_password']];
if (Auth::validate($credentials))
{
password change code;
}
else
{
What should be there?
}
}
不使用 ajax 我们可以 return 重定向到有错误的视图。
如果旧密码错误,使用ajax时else部分发送代码的错误应该是什么?我们也可以匹配 ChangePasswordRequest.php 中的旧密码吗?
return response()->json(['old_password'=> ["Your old password is not correct."] ], 403);
我正在编写更改密码的代码。我的代码如下:
public function changePassword(ChangePasswordRequest $request)
{
$credentials = ['email'=>Auth::user()->email, 'password'=>$request['old_password']];
if (Auth::validate($credentials))
{
password change code;
}
else
{
What should be there?
}
}
不使用 ajax 我们可以 return 重定向到有错误的视图。 如果旧密码错误,使用ajax时else部分发送代码的错误应该是什么?我们也可以匹配 ChangePasswordRequest.php 中的旧密码吗?
return response()->json(['old_password'=> ["Your old password is not correct."] ], 403);