API Routing Laravel 5.5



我有一个基本的控制器,我希望它在那里接收任何json请求。我是api路由的新手。当我使用POST MAN时,我得到了Sorry No Page Found。首先我在get上测试了它,并让它调用了一个简单的返回,但抛出了错误。很抱歉,找不到您要查找的页面我删除了RouteServiceProvider.php中的api前缀,但没有成功。我把我的演示控制器

路由api.php

<?php
use IlluminateHttpRequest;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::get('/test_api/v1', 'TestController@formCheck');

TestController.php

<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class TestController extends Controller
{
public function formCheck(){
return "YES !!!";
}
public function formPost(Request $request)
{
$formData = $request->all();
return response()->json($formData, 201);
}
}

在app/Providers/RouteServiceProvider.php中。

删除前缀('api'(&它看起来应该是这样的。

protected function mapApiRoutes()
{
Route::middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}

最新更新