【发布时间】:2014-01-07 20:19:01
【问题描述】:
return Response::json(array(
'status' => 200,
'posts' => $post->toArray()
), 200);
使用上面的代码,我以 json 格式返回数据。
我已经看到其他返回 json 的 api 以格式化视图返回它。
喜欢:
http://api.steampowered.com/ISteamNews/GetNewsForApp/v0002/?appid=440&count=3&maxlength=300&format=json
但我的将它归为一行。如何使用 laravel 以格式化的方式生成 json?
更新
直到明天我才能测试代码。所以我会接受汤姆的答案。
但这是api
http://laravel.com/api/class-Illuminate.Support.Facades.Response.html
参数是,
$data
$status
$headers
更新
实际上我修改了Illumination的响应类以具有该常量。
【问题讨论】: