Php api路由错误-Laravel 5.3
我正在尝试访问此路由:实际上是api的路由,但使用该路由时,与浏览器的错误相同。Php api路由错误-Laravel 5.3,php,laravel,laravel-5.3,Php,Laravel,Laravel 5.3,我正在尝试访问此路由:实际上是api的路由,但使用该路由时,与浏览器的错误相同。 我的路线尝试1: Route::get('/product-service/payment-notification', "ProductServiceController@notification")->name('productService.notification'); Route::get('/product-service/payment-notification', function(){
我的路线尝试1:
Route::get('/product-service/payment-notification', "ProductServiceController@notification")->name('productService.notification');
Route::get('/product-service/payment-notification', function(){
return \Response::json([
'CREATED' => true
], 201); #also i tryed return 201 directly...
});
Route::get('product-service/payment-notification', [
'as' => 'productService.notification',
'uses' => 'ProductServiceController@notification'
]);
我的路线尝试2:
Route::get('/product-service/payment-notification', "ProductServiceController@notification")->name('productService.notification');
Route::get('/product-service/payment-notification', function(){
return \Response::json([
'CREATED' => true
], 201); #also i tryed return 201 directly...
});
Route::get('product-service/payment-notification', [
'as' => 'productService.notification',
'uses' => 'ProductServiceController@notification'
]);
我的路线尝试3:
Route::get('/product-service/payment-notification', "ProductServiceController@notification")->name('productService.notification');
Route::get('/product-service/payment-notification', function(){
return \Response::json([
'CREATED' => true
], 201); #also i tryed return 201 directly...
});
Route::get('product-service/payment-notification', [
'as' => 'productService.notification',
'uses' => 'ProductServiceController@notification'
]);
我的通知方法
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);
}
我没有发现此方法的存储/日志错误,已被忽略。请帮忙;) 参见Laravel 5.3的说明,它显示默认情况下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');
});
}
因此,您需要在url中添加api前缀。比如说
叫这条路线
Route::get('/product-service/payment-notification', "ProductServiceController@notification")->name('productService.notification');
你需要打电话
不是
另一条路线运行正常*您没有将此路线(可能还有其他路线)包装在带有前缀的路线组中吗?错误说明了什么?不,我没有,这是一条简单的路线。{“error”:“出错了”,“message”:“}这是错误消息。但是拉威尔没有为这条路线写日志。