0

我在控制台中通过这个 cmd 启动服务器,它工作正常

php -S localhost:8000 -t public

当我像这样在邮递员中为流明调用 API 时:

localhost:8000/GitHub/twinfield/public/index.php/user

API适用于插入,但是当我这样调用时:

localhost:8000/GitHub/twinfield/user

错误如下:

(1/1) NotFoundHttpException in RoutesRequests.php (line 226) at Application->handleDispatcherResponse(array(0)) in RoutesRequests.php (line 164) at Application->Laravel\Lumen\Concerns{closure}() 在 RoutesRequests。在 Application->sendThroughPipeline(array(), object(Closure)) 中的 RoutesRequests.php (第 166 行) 在 Application->dispatch(null) 在 RoutesRequests.php (第 107 行) 在 Application->run( ) 在 index.php 中(第 28 行)

我在 routes/web.php 中的路由文件:

$router->get('/', function () use ($router) {
    //print_r('1234');die;
    return $router->app->version();
});

$router->get('user','userController@index');
$router->get('user/{id}','userController@getuser');      
$router->post('user','userController@createuser');
$router->post('user/{id}','userController@updateuser');    
$router->delete('user/{id}','userController@deleteuser');

我已经尝试在 public/index.php 中解决这样的问题,但没有成功。

$request = Illuminate\Http\Request::capture();
$app->run($request);

我正在使用 Xampp 在 localhost 中工作。数据库是 MySQL,PHP 版本是 7.1。

4

2 回答 2

0

先生,您忘记了网址链接,或者可能会错过。它总是在我们启动服务器时(在 laravel 中,命令是 php artisan serve),它总是属于调用它的路径。

就像您的情况一样,您的路径是流明所在的 xampp/htdocs/GItHub/twinfield(我想)。

localhost:8000/GitHub/twinfield/public/index.php/user

所以如果你这样打电话:

localhost:8000/GitHub/twinfield/user

它永远不会起作用,因为您定义了路线:

$router->get('user','userController@index'); 
$router->post('user','userController@createuser');

这就是为什么您必须只使用路线的名称和类型。打开 postman 并使用 type->get 添加这一行:

localhost:8000/user

您将获得数据库中的所有用户。如果你用 type->post 添加这一行。

localhost:8000/user

比您应该使用要保存的表的字段发布正文。

于 2017-11-27T08:34:20.040 回答
0

在尝试了许多解决方案后,我觉得我犯了一个愚蠢的错误。那是网址:

localhost:8000/GitHub/twinfield/user

因为新服务器是由命令启动的,所以它属于那个 url。所以我在邮递员中使用了这个url,而不是post。

localhost:8000/user

你知道它就像一个魅力。在这个解决方案中不需要任何其他东西。

于 2017-11-24T06:54:58.363 回答