2016-11-24 153 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