2016年9月21日 星期三

[Laravel 5.2]How to customize API Dingo json response output

Step 1 :
// config/config.php

    'formats' => [

        'json' => App\Customizes\ResponseFormat\JsonResponseFormat::class,

    ]


Step 2 :

// app/Customizes/ResponseFormat/JsonResponseFormat.php

namespace App\Customizes\ResponseFormat;
class JsonResponseFormat extends \Dingo\Api\Http\Response\Format\Json {

    /**
     * Encode the content to its JSON representation.
     *
     * @param  string  $content
     * @return string
     */
    protected function encode($content) {
        return json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
    }

}

from : https://github.com/dingo/api/issues/143

沒有留言:

wibiya widget