2016-11-24 135 views
1

我試圖訪問此路由:http://anaketesting.tk/product-service/payment-notification真的是api的路由,但是消耗路由,具有與瀏覽器相同的錯誤。
我的路線嘗試1:api路由錯誤 - Laravel 5.3

Route::get('/product-service/payment-notification', "[email protected]")->name('productService.notification'); 

我的路線嘗試2:

Route::get('/product-service/payment-notification', function(){ 
    return \Response::json([ 
     'CREATED' => true 
    ], 201); #also i tryed return 201 directly... 
}); 

我的路線嘗試3:

Route::get('product-service/payment-notification', [ 
    'as' => 'productService.notification', 
    'uses' => '[email protected]' 
]); 

我通知Mé的ThOD

public function notification(Request $request){ 
$date = Carbon::now(); 
$date = $date->format('Ymdhis'); 
file_put_contents(storage_path().'/notification_'.$date.'.json', \Response::json($request)); 

    return \Response::json([ 
     'CREATED' => true 
    ], 201); 
} 

我還沒有使用這種方法的存儲/記錄錯誤,如被忽略。請幫忙;)

+0

另一個路線運行正常* – tesoner

+0

你沒換這條路線(也許是索姆e其他)在一個前綴爲?的路由組中 錯誤說的是什麼? – piotr

+0

不,我沒有,是一個簡單的路線。 {「error」:「出錯了」,「message」:「」} 這是錯誤信息。但是Laravel並沒有寫這條路線的日誌。 – tesoner

回答

2

查看Laravel 5.3的RouteServiceProvider,它顯示api路由被默認分組並且前綴爲api

/app/Providers/RouteServiceProvider.php

/** 
* Define the "api" routes for the application. 
* 
* These routes are typically stateless. 
* 
* @return void 
*/ 
protected function mapApiRoutes() 
{ 
    Route::group([ 
     'middleware' => 'api', 
     'namespace' => $this->namespace, 
     'prefix' => 'api', 
    ], function ($router) { 
     require base_path('routes/api.php'); 
    }); 
} 

因此,您需要在您的網址前綴的API。例如

調用此航線

Route::get('/product-service/payment-notification', "[email protected]")->name('productService.notification'); 

需要調用

http://anaketesting.tk/api/product-service/payment-notification

http://anaketesting.tk/product-service/payment-notification