1

I am working in project where I need to upgrade the Lumer version from 5.1.* to 7.*.

But I have been stuck at the versions 5.4.* and 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:

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.

But after I upgraded to Lumen 5.5.* version, and now when I run any php artisan command, I am getting below error:

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:

{
    "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:

<?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:

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

return $app;
Vicky Dev
  • 1,893
  • 2
  • 27
  • 62

1 Answers1

1

As you may see here $app is no longer used - instead you use $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; the bootstrap/app.php becomes like this

$app->router->group(['namespace' => 'App\Http\Controllers'], function ($router) {
    require __DIR__ . '/../app/Http/routes.php';
});
Ersoy
  • 8,816
  • 6
  • 34
  • 48
  • Yes, I took glance of this a bit when I referred the docs, even if I make the change as you mentioned, in app/Http/routes.php, still the error `Call to undefined method Laravel\Lumen\Application::post()` doesn't go away, do I need to re-run any command after this change ? – Vicky Dev Jun 09 '20 at 20:40
  • in here; https://lumen.laravel.com/docs/5.5/upgrade please search "Updating The Bootstrap File" in the page - there is a detail such as `bootstrap/app.php` @VickyDev – Ersoy Jun 09 '20 at 20:43
  • Yes now I see what you mean, but I am confused, my project only contains Lumen framework, I didn't see Laravel along with it in the code-base, so having said that, I also don't have `../routes/web.php` file, as that is Laravel specific, can you suggest then what should I put there in it's place ? Also can you please update your answer to include the bootstrap/app.php change as well, with detailed and proper explanation than the docs ? – Vicky Dev Jun 09 '20 at 20:45
  • @VickyDev Laravel and Lumen share most of the components - even some part of lumen documentation says that "go check laravel documentation" . Please edit/share your bootstrap/app.php file ("Load The Application Routes" part only) and the location of your routes file – Ersoy Jun 09 '20 at 20:48
  • Please check the updated question, also I have only the default routes.php file i.e. `app/Http/routes.php`. – Vicky Dev Jun 09 '20 at 20:52
  • @VickyDev i modified the answer - please that part with yours - and replace all `$app` with `$router` in your routes.php – Ersoy Jun 09 '20 at 20:54
  • Okay, I think between Lumen 5.4 and 5.5 the structure has changed of routes directory, like in 5.5 there's `routes/web.php` file instead of `app/Http/routes.php` right ? Because with my Lumen 5.5 there's no routes/web.php file created yet... – Vicky Dev Jun 09 '20 at 20:58
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/215616/discussion-between-ersoy-and-vicky-dev). – Ersoy Jun 09 '20 at 20:58