protected function ajaxContent($content)
    {
        $message = null;

        $this->header('Content-Type', 'application/json');

        if ($content instanceof Arrayable) {
            $content = $content->toArray();
        } elseif (is_string($content)) {
            $content = ['content' => $content];
        } elseif (!is_array($content) && !$content instanceof \Exception) {
            return $this->ajaxContent(new \Exception("No valid content has been submitted!", BaseResponse::HTTP_BAD_REQUEST));
        } elseif ($content instanceof \Exception) {

            $this->setStatusCode($content->getCode() < 300 ? BaseResponse::HTTP_BAD_REQUEST : $content->getCode());

            $message = $content->getMessage();

            if ($content instanceof MbException) {
                $content = $content->getMessages();
            } else {
                $content = null;
            }
        }

        $this->original = [
            'meta' => [
                'code'    => $this->getStatusCode(),
                'message' => $message,
            ],
            'data' => $content,
        ];

        $this->getMbAudit()->setResponseType('ajax');
        $this->getMbAudit()->setResponseData($this->original);

        return $this->original;
    }
protected function ajaxContent($content)
    {
        $message = null;

        $this->header('Content-Type', 'application/json');

        if ($content instanceof Arrayable) {
            $content = $content->toArray();
        } elseif (is_string($content)) {
            $content = ['content' => $content];
        } elseif (!is_array($content) && !$content instanceof \Exception) {
            return $this->ajaxContent(new \Exception("No valid content has been submitted!", BaseResponse::HTTP_BAD_REQUEST));
        } elseif ($content instanceof \Exception) {

            $this->setStatusCode($content->getCode() < 300 ? BaseResponse::HTTP_BAD_REQUEST : $content->getCode());

            $message = $content->getMessage();

            if ($content instanceof MbException) {
                $content = $content->getMessages();
            } else {
                $content = null;
            }
        }

        $this->original = [
            'meta' => [
                'code'    => $this->getStatusCode(),
                'message' => $message,
            ],
            'data' => $content,
        ];

        $this->getMbAudit()->setResponseType('ajax');
        $this->getMbAudit()->setResponseData($this->original);

        return $this->original;
    }
protected function ajaxContent ( $ content ) { $ message = null ; $ this -> header ( 'Content-Type' , 'application/json' ) ; if ( $ content instanceof Arrayable ) { $ content = $ content -> toArray ( ) ; } elseif ( is_string ( $ content ) ) { $ content = [ 'content' => $ content ] ; } elseif ( ! is_array ( $ content ) && ! $ content instanceof \ Exception ) { return $ this -> ajaxContent ( new \ Exception ( "No valid content has been submitted!" , BaseResponse :: HTTP_BAD_REQUEST ) ) ; } elseif ( $ content instanceof \ Exception ) { $ this -> setStatusCode ( $ content -> getCode ( ) < 300 ? BaseResponse :: HTTP_BAD_REQUEST : $ content -> getCode ( ) ) ; $ message = $ content -> getMessage ( ) ; if ( $ content instanceof MbException ) { $ content = $ content -> getMessages ( ) ; } else { $ content = null ; } } $ this -> original = [ 'meta' => [ 'code' => $ this -> getStatusCode ( ) , 'message' => $ message , ] , 'data' => $ content , ] ; $ this -> getMbAudit ( ) -> setResponseType ( 'ajax' ) ; $ this -> getMbAudit ( ) -> setResponseData ( $ this -> original ) ; return $ this -> original ; }
Format content for json output

@param array|\Exception $content

@return array[]
Format content for json output