Closed dvigueras closed 3 years ago
I've just discovered there is a pending PR #85 to be merged. That would solve the issue @mpociot
While the pending PR gets merged I fixed it creating a new temporary ServiceProvider in Laravel:
class FixVatCalculatorServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(VatCalculator::class, function ($app) {
return $app->make('\Mpociot\VatCalculator\VatCalculator');
});
}
}
This seems to be merged and released already. Thanks
Yes, it was merged on 2 Jun 2020, thanks.
Hi,
there is an issue with the way that
VatCalculatorServiceProvider
binds theVatCalculator
dependency in Laravel.This is the
registerVatCalculator
method:Instead of using the special PHP
VatCalculator::class
constant which resolves to'Mpociot\VatCalculator\VatCalculator'
the method is using:'\Mpociot\VatCalculator\VatCalculator'
(note the leading slash)In my
vat_calculator.php
config file I have the following config:'business_country_code' => 'ES',
Which gets applied when creating a new instance of
VatCalculator
only ifVatCalculator
is loaded using the Laravel IoC Container.The problem is that if anywhere in my code I declare
VatCalculator
as a dependency, Laravel (5.5 at least) doesn't use the binding provided byVatCalculatorServiceProvider
, and creates the class with a$config = null
.In
php artisan tinker
:The solution would be to use the name without the leading slash in the
registerVatCalculator
method of theVatCalculatorServiceProvider
(The best would be to use the ::class constant).I could send you a PR if you are willing to accept it :)