0
0

Laravel9でLaravel Excelインストール時に、maatwebsite/excelバージョン依存でエラー

Last updated at Posted at 2024-02-26

Laravel9で、Laravel Excelをインストールしようとしたら、エラーが起こったので、残す。

環境

  • Rocky Linux release 9.3
  • PHP 8.0.30
  • Laravel 9.52.16

手順

Laravel Excel インストール

$ composer require psr/simple-cache:^2.0 maatwebsite/excel
$ composer require maatwebsite/excel

config/app.phpのproviders, ailiasesに追記

config/app.php
    'providers' => [
        /*
         * Package Service Providers...
         */
        Maatwebsite\Excel\ExcelServiceProvider::class,  // 追記
    ],
    'aliases' => Facade::defaultAliases()->merge([
        'Excel' => Maatwebsite\Excel\Facades\Excel::class,  // 追記
    ])->toArray(),

config/excel.phpを作成

ここで、エラーが発生した

$ php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config

   BadMethodCallException

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

  at 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() ?

      +9 vendor frames
  10  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

原因

  • maatwebsite/excelのバージョンに問題があった様子
  • `"maatwebsite/excel": "^3.1.48"で、解決した
composer.json
    "require": {
        "maatwebsite/excel": "^3.1.48",  // バージョン指定
    },

確認

$ php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config

   INFO  Publishing [config] assets.

  Copying file [vendor/maatwebsite/excel/config/excel.php] to [config/excel.php] ................................ DONE
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0