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

[5.6] make model factory after method signatures more consistent #23676

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
22 changes: 10 additions & 12 deletions src/Illuminate/Database/Eloquent/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ public function state($class, $state, $attributes)
*
* @param string $class
* @param callable $callback
* @param string $name
* @return $this
*/
public function afterMaking($class, $callback)
public function afterMaking($class, callable $callback, $name = 'default')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this extra type from the definition. It's a breaking change to the signature.

{
$this->afterMaking[$class]['default'][] = $callback;
$this->afterMaking[$class][$name][] = $callback;

return $this;
}
Expand All @@ -133,23 +134,22 @@ public function afterMaking($class, $callback)
* @param callable $callback
* @return $this
*/
public function afterMakingState($class, $state, $callback)
public function afterMakingState($class, $state, callable $callback)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

{
$this->afterMaking[$class][$state][] = $callback;

return $this;
return $this->afterMaking($class, $callback, $state);
}

/**
* Define a callback to run after creating a model.
*
* @param string $class
* @param callable $callback
* @param string $name
* @return $this
*/
public function afterCreating($class, $callback)
public function afterCreating($class, callable $callback, $name = 'default')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

etc

{
$this->afterCreating[$class]['default'][] = $callback;
$this->afterCreating[$class][$name][] = $callback;

return $this;
}
Expand All @@ -162,11 +162,9 @@ public function afterCreating($class, $callback)
* @param callable $callback
* @return $this
*/
public function afterCreatingState($class, $state, $callback)
public function afterCreatingState($class, $state, callable $callback)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to add this, please do it on master.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did and @taylorotwell said to put it here. #23670

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature has not been tagged yet so no worries about breaking changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, good.

{
$this->afterCreating[$class][$state][] = $callback;

return $this;
return $this->afterCreating($class, $callback, $state);
}

/**
Expand Down