laravelcontrollercomposer-phplaravel-8code-composer

code error when creating controller in laravel


code error when creating controller in laravel php artisan make:Controller KmsController

RuntimeException
Unable to detect application namespace.
Illuminate\Console\GeneratorCommand::rootNamespace()

and I tried: composer dump-autoload

In JsonFile.php line 340:

"./composer.json" does not contain valid JSON
Parse error on line 65:
...fer-stable": true}{ "require": {
--------------------^
Expected one of: 'EOF', '}', ',', ']'


Solution

  • If your json you posted is exactly like that, your error is at the bottom, see this part:

    {
        "config": {
            "optimize-autoloader": true,
            "preferred-install": "dist",
            "sort-packages": true
        },
        "minimum-stability": "dev",
        "prefer-stable": true
    } // HERE IS THE ERROR
    {
        "require": {
            "phpoffice/phpspreadsheet": "^1.23"
        },
        "config": {
            "platform": {
                "php": "7.3"
            }
        }
    }
    

    You have to move the text inside the require (at the bottom) into the top where you also have require, same for config...

    Your JSON should be like this:

    {
        "name": "laravel/laravel",
        "type": "project",
        "description": "The Laravel Framework.",
        "keywords": ["framework", "laravel"],
        "license": "MIT",
        "require": {
            "php": "^7.3|^8.0",
            "consoletvs/charts": "6.*",
            "fruitcake/laravel-cors": "^2.0",
            "guzzlehttp/guzzle": "^7.0.1",
            "ladumor/laravel-pwa": "^0.0.3",
            "laravel/framework": "^8.75",
            "laravel/sanctum": "^2.11",
            "laravel/tinker": "^2.5",
            "phpoffice/phpspreadsheet": "^1.25",
            "phpoffice/phpspreadsheet": "^1.23"
        },
        "require-dev": {
            "facade/ignition": "^2.5",
            "fakerphp/faker": "^1.9.1",
            "laravel/sail": "^1.0.1",
            "mockery/mockery": "^1.4.4",
            "nunomaduro/collision": "^5.10",
            "phpunit/phpunit": "^9.5.10"
        },
        "autoload": {
            "psr-4": {
                "App\\": "app/",
                "Database\\Factories\\": "database/factories/",
                "Database\\Seeders\\": "database/seeders/"
            }
        },
        "autoload-dev": {
            "psr-4": {
                "Tests\\": "tests/"
            }
        },
        "scripts": {
            "post-autoload-dump": [
                "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
                "@php artisan package:discover --ansi"
            ],
            "post-update-cmd": [
                "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
            ],
            "post-root-package-install": [
                "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
            ],
            "post-create-project-cmd": [
                "@php artisan key:generate --ansi"
            ]
        },
        "extra": {
            "laravel": {
                "dont-discover": []
            }
        },
        "config": {
            "optimize-autoloader": true,
            "preferred-install": "dist",
            "sort-packages": true,
            "platform": {
                "php": "7.3"
            }
        },
        "minimum-stability": "dev",
        "prefer-stable": true
    }
    

    BUT, you can see you now have the same package, twice, with 2 different versions:

    "require": {
        "php": "^7.3|^8.0",
        "consoletvs/charts": "6.*",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "ladumor/laravel-pwa": "^0.0.3",
        "laravel/framework": "^8.75",
        "laravel/sanctum": "^2.11",
        "laravel/tinker": "^2.5",
        "phpoffice/phpspreadsheet": "^1.25",
        "phpoffice/phpspreadsheet": "^1.23"
    },
    

    You will have to know if phpoffice/phpspreadsheet needs to be ^1.25 or ^1.23. I will assume using 1.25 is fine