menu

Questions & Answers

BadMethodCallException Method Illuminate\Foundation\Application::share does not exist

I'm trying to import and export with Laravel, I followed several guides, and I didn't manage to implement something stable.

when running php artisan make:import UsersImport --model=User

The console gives me the following errors:

PS C:\xampp\htdocs\LARAVEL\excel> php artisan make:import UsersImport --model=User

   BadMethodCallException 

  Method Illuminate\Foundation\Application::share does not exist.

  at C:\xampp\htdocs\LARAVEL\excel\vendor\laravel\framework\src\Illuminate\Macroable\Traits\Macroable.php:113
    109▕      */
    110▕     public function __call($method, $parameters)
    111▕     {
    112▕         if (! static::hasMacro($method)) {
  ➜ 113▕             throw new BadMethodCallException(sprintf(
    114▕                 'Method %s::%s does not exist.', static::class, $method
    115▕             ));
    116▕         }
    117▕

  i   Bad Method Call: Did you mean Illuminate\Foundation\Application::isShared() ?

  1   C:\xampp\htdocs\LARAVEL\excel\vendor\maatwebsite\excel\src\Maatwebsite\Excel\ExcelServiceProvider.php:156
      Illuminate\Foundation\Application::__call("share")

  2   C:\xampp\htdocs\LARAVEL\excel\vendor\maatwebsite\excel\src\Maatwebsite\Excel\ExcelServiceProvider.php:58
      Maatwebsite\Excel\ExcelServiceProvider::bindClasses()

Mi composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.0.2",
        "barryvdh/laravel-dompdf": "^2.0",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^9.19",
        "laravel/sanctum": "^3.0",
        "laravel/tinker": "^2.7",
        "maatwebsite/excel": "*",
        "orchestra/testbench": "^7.11",
        "phpoffice/phpspreadsheet": "dev-NumberFormatMask-Helpers",
        "predis/predis": "^2.0",
        "psr/simple-cache": "1.0"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^6.1",
        "phpunit/phpunit": "^9.5.10",
        "spatie/laravel-ignition": "^1.0"
    },
    "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,
        "allow-plugins": {
            "pestphp/pest-plugin": true
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

php artisan make:import UsersImport --model=User

You should have created an import class in app/Imports

Comments:
2023-01-23 23:30:05
In English, please, or try your question at Stack Overflow en español.
2023-01-23 23:30:05
github.com/SpartnerNL/Laravel-Excel/issues/3489 might be of some help, though
Answers(0) :