Skip to content

Commit 0054c26

Browse files
authored
[11.x] Deprecate Factory::$modelNameResolver (#54736)
Instead of removing the `$modelNameResolver` property entirely, which breaks any user-land and 3rd-party uses of it, this re-introduces the original property, but marks it as deprecated so that developers have a chance to migrate correctly without having to avoid other Laravel updates.
1 parent 610155c commit 0054c26

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Illuminate/Database/Eloquent/Factories/Factory.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ abstract class Factory
113113
*/
114114
public static $namespace = 'Database\\Factories\\';
115115

116+
/**
117+
* @deprecated use $modelNameResolvers
118+
*
119+
* @var callable(self): class-string<TModel>
120+
*/
121+
protected static $modelNameResolver;
122+
116123
/**
117124
* The default model name resolvers.
118125
*
@@ -810,7 +817,7 @@ public function modelName()
810817
return $this->model;
811818
}
812819

813-
$resolver = static::$modelNameResolvers[static::class] ?? static::$modelNameResolvers[self::class] ?? function (self $factory) {
820+
$resolver = static::$modelNameResolvers[static::class] ?? static::$modelNameResolvers[self::class] ?? static::$modelNameResolver ?? function (self $factory) {
814821
$namespacedFactoryBasename = Str::replaceLast(
815822
'Factory', '', Str::replaceFirst(static::$namespace, '', $factory::class)
816823
);
@@ -931,6 +938,7 @@ protected static function appNamespace()
931938
*/
932939
public static function flushState()
933940
{
941+
static::$modelNameResolver = null;
934942
static::$modelNameResolvers = [];
935943
static::$factoryNameResolver = null;
936944
static::$namespace = 'Database\\Factories\\';

0 commit comments

Comments
 (0)