Skip to content
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

[9.x] Defers expanding callables on Factories #42241

Merged
merged 1 commit into from
May 3, 2022
Merged

[9.x] Defers expanding callables on Factories #42241

merged 1 commit into from
May 3, 2022

Conversation

DarkGhostHunter
Copy link
Contributor

What?

When defining attributes on a Factory, this small fix will defer callables to be resolved after all other non-callables are set in the definition array.

This makes this code safe to work with:

public function definition()
{
    return [
        'first' => fn ($attributes) => $attributes['last'] + 1, // 4
        'last' => 3
    ];
}
  1. last is resolved first.
  2. first will be resolved last.

This avoids making the developer having to push callables to the end of the definition array.

@taylorotwell taylorotwell merged commit e040831 into laravel:9.x May 3, 2022
@DarkGhostHunter DarkGhostHunter deleted the feat/factory-definition-order branch May 3, 2022 23:25
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.

None yet

2 participants