8000 [11.x] Deprecate `Factory::$modelNameResolver` by samlev · Pull Request #54736 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[11.x] Deprecate Factory::$modelNameResolver #54736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[11.x] Deprecate Factory::$modelNameResolver
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.
  • Loading branch information
samlev committed Feb 21, 2025
commit 38bd7e2d9306359e5b7adce3417859b43aa4448b
10 changes: 9 additions & 1 deletion src/Illuminate/Database/Eloquent/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ abstract class Factory
*/
public static $namespace = 'Database\\Factories\\';

/**
* @deprecated use $modelNameResolvers
*
* @var callable(self): class-string<TModel>
*/
protected static $modelNameResolver;

/**
* The default model name resolvers.
*
Expand Down Expand Up @@ -810,7 +817,7 @@ public function modelName()
return $this->model;
}

$resolver = static::$modelNameResolvers[static::class] ?? static::$modelNameResolvers[self::class] ?? function (self $factory) {
$resolver = static::$modelNameResolvers[static::class] ?? static::$modelNameResolvers[self::class] ?? static::$modelNameResolver ?? function (self $factory) {
$namespacedFactoryBasename = Str::replaceLast(
'Factory', '', Str::replaceFirst(static::$namespace, '', $factory::class)
);
Expand Down Expand Up @@ -931,6 +938,7 @@ protected static function appNamespace()
*/
public static function flushState()
{
static::$modelNameResolver = null;
static::$modelNameResolvers = [];
static::$factoryNameResolver = null;
static::$namespace = 'Database\\Factories\\';
Expand Down
Loading
0