修改app/Exceptions/Handler.php文件內容
use Illuminate\Validation\ValidationException;
修改render函數
public function render($request, Throwable $exception) { if ($exception instanceof ValidationException) { return response()->json([ 'code' => 422, 'msg' => '調用參數錯誤', 'data' => $exception->errors(), ], 422); } return parent::render($request, $exception); }
結果: