Laravel-modules: Target class [Illuminate\Database\Eloquent\Factory] does not exist.

Created on 21 Sep 2020  Â·  4Comments  Â·  Source: nWidart/laravel-modules

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")

Most helpful comment

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FoksVHox picture FoksVHox  Â·  11Comments

KyawNaingTun picture KyawNaingTun  Â·  16Comments

echemik picture echemik  Â·  10Comments

bhattraideb picture bhattraideb  Â·  12Comments

uncodable picture uncodable  Â·  21Comments