Skip to content

Conversation

@villfa
Copy link
Contributor

@villfa villfa commented Jul 31, 2024

The callback passed as an argument to afterCreating() is always invoked with 2 parameters, the 2nd parameter being the parent model (see callAfterCreating()).

Before this change, PHPStan could raise this kind of error:

 Parameter #1 $callback of method Illuminate\Database\Eloquent\Factories\Factory<Illuminate\Database\Eloquent\Model>::afterCreating() expects Closure(Illuminate\Database\Eloquent\Model): mixed, Closure(App\Models\MyModel, mixed): void given.  
 🪪  argument.type                                                                                                                                                                                                                                  
 💡 Parameter #2 $parent of passed callable is required but accepting callable does not have that parameter. It will be called without it. 

Here're some reproducers:

@taylorotwell taylorotwell merged commit db768e4 into laravel:10.x Aug 1, 2024
@villfa villfa deleted the fix/factory-after-creating branch August 1, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants