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

[12.x] Refactor Eloquent Builder: Add new addWhereRelationCallback method to reduce code duplication #55300

Closed
wants to merge 1 commit into from

Conversation

ezequidias
Copy link

This PR introduces a new internal method called addWhereRelationCallback, designed to remove duplicated logic found across several relationship-based query methods in Eloquent.

Previously, the following methods contained nearly identical closure logic to apply conditions on related models:

  • withWhereRelation
  • whereRelation
  • orWhereRelation
  • whereDoesntHaveRelation
  • orWhereDoesntHaveRelation

Each of these methods used an inline closure to check if the $column parameter was a Closure or a column name, then applied the condition accordingly.

By introducing addWhereRelationCallback, we now reuse a single method that handles this logic, resulting in:

  • Cleaner and more maintainable code
  • Less duplication
  • More consistent behavior across methods

No behavior has been changed—this is a pure refactor aimed at improving code quality.

@ezequidias ezequidias marked this pull request as draft April 6, 2025 19:19
@ezequidias ezequidias marked this pull request as ready for review April 7, 2025 00:11
@taylorotwell
Copy link
Member

I think it's fine for now.

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