简体   繁体   English

Lumen:在 routes.php 第 17 行:升级到 5.5 后调用未定义的方法 Laravel\Lumen\Application::post()。*

[英]Lumen: In routes.php line 17: Call to undefined method Laravel\Lumen\Application::post(), after upgrade to 5.5.*

I am working in project where I need to upgrade the Lumer version from 5.1.* to 7.*.我正在从事需要将 Lumer 版本从 5.1.* 升级到 7.* 的项目。

But I have been stuck at the versions 5.4.* and 5.5.* .但我一直停留在5.4.*5.5.*版本。 Where in 5.4.* when I ran the built-in php server php -S localhost:8000 -t./public and visited the URL http:\\localhost:8000 , I got the below error: Where in 5.4.* when I ran the built-in php server php -S localhost:8000 -t./public and visited the URL http:\\localhost:8000 , I got the below error:

Call to undefined method ...\Application->welcome()

But I upgraded to next version hoping that would solve this issue, as I hadn't changed any of files outside vendor folder.但我升级到下一个版本希望能解决这个问题,因为我没有更改vendor文件夹之外的任何文件。

But after I upgraded to Lumen 5.5.* version, and now when I run any php artisan command, I am getting below error:但是在我升级到 Lumen 5.5.* 版本后,现在当我运行任何php artisan命令时,我收到以下错误:

In routes.php line 17:
  Call to undefined method Laravel\Lumen\Application::post()

Can anyone share idea on what's wrong and how to fix both the aforementioned errors?任何人都可以分享有关出了什么问题以及如何解决上述两个错误的想法吗?

This is composer.json file of project, just in case it helps:这是项目的 composer.json 文件,以防万一:

{
    "name": "laravel/lumen",
    "description": "The Laravel Lumen Framework.",
    "keywords": ["framework", "laravel", "lumen"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/lumen-framework": "5.5.*",
        "vlucas/phpdotenv": "~2.2"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/"
        ]
    },
    "autoload-dev": {
        "classmap": [
            "tests/"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

app/Http/routes.php: app/Http/routes.php:

<?php
    date_default_timezone_set('America/Chicago');
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/


//$app->group(['middleware' => 'FilterInput'], function($app) {

    $app->post('app_details', ['as' => 'app_details', 'uses' => 'App\Http\Controllers\Details@set_app_details']);
    $app->post('phone_details', ['as' => 'phone_details', 'uses' => 'App\Http\Controllers\Details@set_phone_details']);
    $app->post('app_search', ['as' => 'from_search', 'uses' => 'App\Http\Controllers\Details@set_search_details']);
    $app->post('app_lead', ['as' => 'from_search', 'uses' => 'App\Http\Controllers\Details@set_lead_details']);
    $app->post('survey', ['as' => 'survey', 'uses' => 'App\Http\Controllers\Survey@set_data']);


    //capture all routes regardless
    $app->get('{path:.*}', function() use ($app) {
        return $app->welcome();
    });

//});

bootstrap/app.php excerpt: bootstrap/app.php摘录:

...
...
require __DIR__.'/../app/Http/routes.php';

return $app;

As you may see here $app is no longer used - instead you use $router .正如您在此处看到的,不再使用$app - 而是使用$router

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

The previous version was like this以前的版本是 这样

After updating the routes by replacing $app with $router ;通过将$app替换为$router来更新路线后; the bootstrap/app.php becomes like this bootstrap/app.php 变成这样

$app->router->group(['namespace' => 'App\Http\Controllers'], function ($router) {
    require __DIR__ . '/../app/Http/routes.php';
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM