Hi Guys
Looking for assistance, am currently learning nWidart/laravel-modules to structure my application. Issues arise after creating Module and running the publish command.
I am getting the following exception
C:\~\Projects\LaravelModule\modularapp>php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
Illuminate\Contracts\Container\BindingResolutionException
Target class [Illuminate\Database\Eloquent\Factory] does not exist.
at C:\~\Projects\LaravelModule\modularapp\vendor\laravel\framework\src\Illuminate\Container\Container.php:812
808â–•
809â–• try {
810â–• $reflector = new ReflectionClass($concrete);
811â–• } catch (ReflectionException $e) {
➜ 812▕ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
813â–• }
814â–•
815â–• // If the type is not instantiable, the developer is attempting to resolve
816â–• // an abstract type such as an Interface or Abstract Class and there is
1 [internal]:0
Illuminate\Foundation\Application::Illuminate\Foundation{closure}(Object(Modules\Account\Providers\AccountServiceProvider))
2 C:\~\Projects\LaravelModule\modularapp\vendor\laravel\framework\src\Illuminate\Container\Container.php:810
ReflectionException::("Class Illuminate\Database\Eloquent\Factory does not exist")
Just install the laravel/legacy-factories package if you are using Factories, or simply comment the $this->registerFactories(); inside boot method in each of your ModuleServiceProviders.
Thanks bojcheski
I will try both methods, i also searched on previous threads and found a fix, not sure if its best practice but it works. see the snipet below.
public function registerFactories()
{
if (! app()->environment('production') && $this->app->runningInConsole()) {
$this->loadFactoriesFrom(module_path($this->moduleName, '$FACTORIES_PATH$'));
}
}
this works and my only concern is its not done on the module creation as you have to manually update the Providers in the module.
Regards
https://github.com/nWidart/laravel-modules/issues/1050#issuecomment-700700957 Maybe a less hacky way to fix this issue :)
Fixed in 8.0, supporting laravel 8.
Most helpful comment
Just install the
laravel/legacy-factoriespackage if you are using Factories, or simply comment the$this->registerFactories();insidebootmethod in each of your ModuleServiceProviders.