我有一个带控制器的RESTful API,它应该在我的Android应用程序被命中时返回JSON响应,当它被Web浏览器命中时应该返回"视图".我甚至不确定我是以正确的方式接近这一点.我正在使用Laravel,这就是我的控制器的样子
class TablesController extends BaseController { public function index() { $tables = Table::all(); return Response::json($tables); } }
我需要这样的东西
class TablesController扩展BaseController {
public function index() { $tables = Table::all(); if(beingCalledFromWebBrowser){ return View::make('table.index')->with('tables', $tables); }else{ //Android return Response::json($tables); } }
看看答案如何相互不同?