Laravel框架之通过url确定返回错误信息格式

public function render($request, Exception $exception)
    {

        if(!empty($exception)){
            $url = URL::current();
            $urlData = parse_url($url);
            $midware = substr($urlData['path'],0,6);
            if($midware != '/admin'){
                echo '参数缺失,系统错误!';exit;
            }
            return response()->json(['message'=>'参数缺失,系统异常!', 'code'=>99999]);
        }
        return parent::render($request, $exception);
    }

你可能感兴趣的:(laravel,Laravel)