mollie / laravel-mollie

Mollie API client wrapper for Laravel & Mollie Connect provider for Laravel Socialite
https://www.mollie.com/
MIT License
322 stars 62 forks source link

Mollie facade not autoloading in Laravel 9: Target class [mollie] does not exist. #226

Closed vHeemstra closed 1 year ago

vHeemstra commented 1 year ago

I'm not sure what changed, but in a new, default, Laravel (v9) application, the documented method of including this package results in Laravel not able to find the facade class:

Target class [mollie] does not exist.

Adding Mollie\Laravel\MollieServiceProvider::class, to the providers key of the array returned by config/app.php, fixed this.

Maybe the docs need updating or the package itself (if this step should not be needed).

https://github.com/mollie/laravel-mollie/blob/039eec4f8e8a138e0539d77e0dcce3bc34df25f8/README.md?plain=1#L51

Tested with:

Naoray commented 1 year ago

Hello @vHeemstra,

how did you attempt to access the Mollie facade exactly? After requiring this package with composer require mollie/laravel-mollie you should see the package listed in the Discovering Packages Info (s. screenshot). Afterwards you should be able to access it by calling Mollie::api()->….

Screenshot 2023-02-28 at 10 38 05
vHeemstra commented 1 year ago

I followed the steps as described in the readme. This is the log from re-running this command:

image

In my controller I include the class references:

use Mollie\Laravel\Facades\Mollie;
use Mollie\Api\Exceptions\ApiException;

And inside the controller method (that handles a page request) I use this to get the available payment methods:

try {
  $mollieMethods = Mollie::api()->methods()->allActive([
    'sequenceType' => 'oneoff',
    'amount' => [
      'currency' => 'EUR',
      'value' => number_format((float) $payment->total, 2, '.', ''),
    ],
    'include' => 'issuers',
  ]);
} catch (ApiException $e) {
  report($e);
}
vHeemstra commented 1 year ago

Did some additional testing. The autoload works out-of-the-box on my local dev, but the above mentioned error is thrown on my online test environment. Although I did update the vendors folder and composer.* files, I might missed something Laravel-related there. (Probably the Laravel cache files.)

Anyway, the issue is with my composer update online I think and not with this package. 😄

Naoray commented 1 year ago

@vHeemstra, yes you have to delete the cache in order for this to work. Otherwise it won’t pick up on newly registered packages I think