Skip to content

[13.x] Exception is thrown when model is created using factory #59260

@gabrielrbarbosa

Description

@gabrielrbarbosa

Laravel Version

13.0.0

PHP Version

8.5.0

Database Driver & Version

MariaDB 11.4

Description

Related to https://github.com/laravel/framework/pull/55685/changes

Database\Seeders\ProdutoTableSeeder ...................................................................................................... RUNNING  

   LogicException 

  The [Illuminate\Database\Eloquent\Model::bootIfNotBooted] method may not be called on model [App\Models\Produto\Categoria\SubcategoriaProduto] while it is being booted.

  at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:334
    330▕     protected function bootIfNotBooted()
    331▕     {
    332▕         if (! isset(static::$booted[static::class])) {
    333▕             if (isset(static::$booting[static::class])) {
  ➜ 334▕                 throw new LogicException('The ['.__METHOD__.'] method may not be called on model ['.static::class.'] while it is being booted.');
    335▕             }
    336▕ 
    337▕             static::$booting[static::class] = true;
    338▕ 

      +2 vendor frames 

  3   app/Models/Produto/Categoria/SubcategoriaProduto.php:52
      Illuminate\Database\Eloquent\Model::observe()
      +9 vendor frames 

  13  database/factories/Produto/ProdutoFactory.php:51
      Illuminate\Database\Eloquent\Factories\Factory::create([])

Seeder is basically this: $produtoFactory = Produto::factory()->create(); and product factory calls SubcategoriaProduto::factoy();

Steps To Reproduce

php artisan migrate:fresh --seed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions