2017-04-04 19 views
-1

我在我的web应用程序中使用laravel 4.2生成html视图的正常方法..我想执行REST调用新的路由,使用相同的逻辑在我的控制器函数(它返回html视图)..什么是最好的技术来做到这一点? ..如何使相同的功能服务于网络和移动应用程序(通过REST API)。laravel 4.2生成web视图和来自同一个逻辑的REST调用

回答

0

您可以使用Request::wantsJson()方法,如here所述。

if (Request::wantsJson()) { 
    // Perform REST API stuff here 
} 
else { 
    // Normal requests/returning views here 
}