skip to Main Content

I’ve installed maatwebsite/excel with the command composer require maatwebsite/excel from command line on my laravel project. I’ve set the correct aliases and providers following the guide but when I run php artisan make:export ExportTimesheet --model=Timesheet, it throws an error:

BadMethodCallException Method IlluminateFoundationApplication::share does not exist

This is the method that generates the error:

protected function bindClasses()
{
    // Bind the format identifier
    $this->app['excel.identifier'] = $this->app->share(function($app) {
        return new FormatIdentifier($app['files']);
    });
}

My providers and aliases are:

    'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        IlluminateAuthAuthServiceProvider::class,
        IlluminateBroadcastingBroadcastServiceProvider::class,
        IlluminateBusBusServiceProvider::class,
        IlluminateCacheCacheServiceProvider::class,
        IlluminateFoundationProvidersConsoleSupportServiceProvider::class,
        IlluminateCookieCookieServiceProvider::class,
        IlluminateDatabaseDatabaseServiceProvider::class,
        IlluminateEncryptionEncryptionServiceProvider::class,
        IlluminateFilesystemFilesystemServiceProvider::class,
        IlluminateFoundationProvidersFoundationServiceProvider::class,
        IlluminateHashingHashServiceProvider::class,
        IlluminateMailMailServiceProvider::class,
        IlluminateNotificationsNotificationServiceProvider::class,
        IlluminatePaginationPaginationServiceProvider::class,
        IlluminatePipelinePipelineServiceProvider::class,
        IlluminateQueueQueueServiceProvider::class,
        IlluminateRedisRedisServiceProvider::class,
        IlluminateAuthPasswordsPasswordResetServiceProvider::class,
        IlluminateSessionSessionServiceProvider::class,
        IlluminateTranslationTranslationServiceProvider::class,
        IlluminateValidationValidationServiceProvider::class,
        IlluminateViewViewServiceProvider::class,
        MaatwebsiteExcelExcelServiceProvider::class,

        /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */
        AppProvidersAppServiceProvider::class,
        AppProvidersAuthServiceProvider::class,
        // AppProvidersBroadcastServiceProvider::class,
        AppProvidersEventServiceProvider::class,
        AppProvidersRouteServiceProvider::class,

    ],

    /*
     |--------------------------------------------------------------------------
     | Class Aliases
     |--------------------------------------------------------------------------
     |
     | This array of class aliases will be registered when this application
     | is started. However, feel free to register as many as you wish as
     | the aliases are "lazy" loaded so they don't hinder performance.
     |
     */

    'aliases' => Facade::defaultAliases()->merge([
        // 'ExampleClass' => AppExampleExampleClass::class,
        'Excel' => MaatwebsiteExcelFacadesExcel::class,
    ])->toArray(),

This is my composer.json:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.0.2",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^9.19",
        "laravel/sanctum": "^3.0",
        "laravel/tinker": "^2.7",
        "maatwebsite/excel": "*",
        "spatie/laravel-permission": "^5.8"
    },
    "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": "stable",
    "prefer-stable": true
}

2

Answers


  1. The error is caused by gd and zip extension not being enabled by default in your xampp / wamp server..
    to resolved this …
    1 open your php ini file
    2. go to gd extension and remove the ; before gd entension, likewise zip-extension
    3. save the file again
    4. restart your server
    5. then re-install the package again : composer require maatwebsite/excel

    • it should work, because that was how I’m able to resolved mine too when I came across this error.
    Login or Signup to reply.
  2. I am using laravel 9 .After running following steps everything seems to be fine.

    1. Go to composer.json
    2. Update "maatwebsite/excel": "3.1.48",
    3. Run composer update
    4. Go to config->app.php
    5. Add to providers MaatwebsiteExcelExcelServiceProvider::class,
    6. Add to aliases ‘Excel’ =>MaatwebsiteExcelFacadesExcel::class,
    7. Run composer dump-autoload
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search