Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validators do not get added due to deferred service provider #14

Open
hackel opened this issue Oct 2, 2018 · 5 comments
Open

Validators do not get added due to deferred service provider #14

hackel opened this issue Oct 2, 2018 · 5 comments

Comments

@hackel
Copy link

hackel commented Oct 2, 2018

I just upgraded from 0.5.2 and discovered that the validations no longer work, throwing a BadMethodCallException: Method Illuminate\Validation\Validator::validateCca2 does not exist. I discovered that the validator extensions were not being loaded at all, and traced that back to the service provider now being deferred.

As a workaround, I just added app('pragmarx.countries'); to my own AppServiceProvider to manually resolve the provider on every request, which then registers the validator extensions, and everything is happy again.

I'm not sure of the best solution to this issue. Perhaps it would be best to convert the validation extensions to Rule objects that will resolve the provider when needed without having to disable deferred loading all together.

@wissejel
Copy link

wissejel commented Oct 3, 2018

I'm having the exact same problem. To me it looks like it became a problem since laravel 5.7.

@hackel could you explain your workaround in a little more detail? I can't seem to get it working. Thanks.

@hackel
Copy link
Author

hackel commented Oct 4, 2018

@handyface I literally just added app('pragmarx.countries'); to the end of my AppServiceProvider::boot method. This causes the deferred \PragmaRX\CountriesLaravel\Package\ServiceProvider to get loaded and cached on every request just like a regular, non-deferred provider.

This isn't really ideal, since only a a couple of my routes actually require the validator, and so the service gets loaded for nothing. I also thought about using a middleware to load the provider prior to hitting my FormRequest class only when it is needed, but haven't gotten around to it yet.

@wissejel
Copy link

@hackel Thanks for the response. I tried it but for me this produces errors, so I'm removing the validation altogether for now.

@reefki
Copy link

reefki commented Oct 27, 2018

Add app('pragmarx.countries'); to AppServiceProvider does the trick, thanks!

@radd2004
Copy link

Also worked when I call app('pragmarx.countries'); just before calling $this->validate in my controller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants