2017-04-04 18 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 
}