Skip to content

modelNameResolvers[self::class] Infinite Loop #54812

@YurstoreTony

Description

@YurstoreTony

Laravel Version

11.44.0

PHP Version

8.3

Database Driver & Version

No response

Description

This is in a way, a follow up to #54719 .

As mentioned in that ticket, removing ?? static::$modelNameResolvers[self::class] seems to fix the issue.

It seems the segment ?? static::$modelNameResolver was added since that issue, which I expect was in response to the specific error given in that issue ticket. That makes sense, a conditional handling of the deprecated property.

However, ?? static::$modelNameResolvers[self::class] continues to be troublesome, seemingly sending seeders using Factory creation into an infinite loop. Would love a discussion on what might be specifically causing this.

The use of self::class on line 820 of \Illuminate\Database\Eloquent\Factories\Factory.php returns Illuminate\Database\Eloquent\Factories\Factory.
It appears as if the intention is to use static::class and self::class as indices for the new modelNameResolvers Array, but the use of self::class here is creating an infinite recursion. It is probably not intended to return the Factory.php class, but the model class using HasFactory trait.

Can someone shed some light on this if I'm missing something?

Image

Steps To Reproduce

  1. Add a ::factory()->create() call to a seeder.
  2. Use HasFactory on the model calling it.
  3. Run --seed on migration, running that seeder.
  4. The seeding job will get stuck, and will infinitely loop through modelName() on Factory class

php 8.3
laravel 11.44.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions