Laravel-modules: need update for laravel 8

Created on 9 Sep 2020  Â·  8Comments  Â·  Source: nWidart/laravel-modules

Hello;
need some changes about the file system for laravel 8.
When a new module created it looks for [Illuminate\Database\Eloquent\Factories\Factory] but in laravel 8 it is changed to Illuminate\Database\Eloquent\Factories\Factory.

All 8 comments

Same problem.
I changed use [Illuminate\Database\Eloquent\Factory;] to [use Illuminate\Database\Eloquent\Factories\Factory;]
Illuminate\Contracts\Container\BindingResolutionException

Target [Illuminate\Database\Eloquent\Factories\Factory] is not instantiable.

at C:\xampp\htdocs\laravel-modular\vendor\laravel\framework\src\Illuminate\Con
tainer\Container.php:1017
1013â–• } else {
1014â–• $message = "Target [$concrete] is not instantiable.";
1015â–• }
1016â–•
➜ 1017▕ throw new BindingResolutionException($message);
1018â–• }
1019â–•
1020â–• /**
1021â–• * Throw an exception for an unresolvable primitive.

1 C:\xampp\htdocs\laravel-modular\vendor\laravel\framework\src\Illuminate\Co
ntainer\Container.php:818
Illuminate\Container\Container::notInstantiable("Illuminate\Database\Eloqu
ent\Factories\Factory")

2 C:\xampp\htdocs\laravel-modular\vendor\laravel\framework\src\Illuminate\Co
ntainer\Container.php:691
Illuminate\Container\Container::build("Illuminate\Database\Eloquent\Factor
ies\Factory")

possible solution ??..

  /**
     * Register an additional directory of factories.
     *
     * @return void
     */
    public function registerFactories()
    {
        if (! app()->environment('production') && $this->app->runningInConsole()) {
            $this->loadFactoriesFrom(module_path($this->moduleName, 'Database/factories'));
        }
    }

@Plasto13 I think this workaround needs the laravel/legacy-factories package because the ones generated are not factories classes also the models should include the factories trait by default.

@nWidart Is there a release time for the L8 upgrade?

1057 Try this.

hello, is there an approximate date planned for the support update to laravel 8 ?, thanks

This

1057.

This have helped me to solve the issue.
But need permeant solution by support release to Laravel 8.
Thank you.

!!!the loadFactoriesFrom method should not be used, it's deprecated and it will be removed from Laravel in a future version!!!

What you should do, is overwrite the newFactory() method, that the HasFactory trait provides, and just register the factory there. I would be happier for a more "global" solution but this seems to be a good solution and doing it the way laravel intended it to. Hacking stuff will bite you in the future :)

/**
 * Create a new factory instance for the model.
 *
 * @return Factory
 */
protected static function newFactory(): Factory
{
    return FactoryClass::new();
}

Support has been added.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guirociozanini picture guirociozanini  Â·  4Comments

sandeepk2304 picture sandeepk2304  Â·  3Comments

pawlox picture pawlox  Â·  4Comments

quentingosset picture quentingosset  Â·  4Comments

NexxusPlexx picture NexxusPlexx  Â·  4Comments