【发布时间】:2017-11-23 03:47:34
【问题描述】:
我正在使用 Laravel 5.3 制作后端 API
其中一个 API 是 OnaController 中的这个,它将返回 Json 格式:
public function index()
{
$limit = Input::get('limit') ?: 10;
if ($limit < 1 or $limit > 100) {
$limit = 10;
}
$ona_datas = Onaio::where('status', '<>', 4)->paginate($limit);
return $this->respondWithPagination(
$ona_datas,
$this->onaTransformer->transformCollection($ona_datas->all())
);
}
名为ona_list.php的前端文件放在公共文件夹(/public)
我的问题是如何将文件作为视图然后将 json 传递给它? 我想用相同的 URL 打开文件 (my_website.com/ona)
这是我迄今为止尝试过的:
return view(asset('ona_list.php')但它抛出了InvalidArgumentException in FileViewFinder.php line 137: View [http:..localhost:8000.ona_list.php] not found.return redirect(asset('ona_list.php')) ->with(json_decode($this->respondWithPagination($ona_datas, $this->onaTransformer->transformCollection( $ona_datas->all()))));但网址更改为 my_website.com\ona_list.php 且数据未显示
【问题讨论】:
-
你的 routes/api.php 是什么样的?
标签: php json laravel api laravel-5