Skip to content

Comments

Add support for Laravel scope attributes in joinRelationship callbacks#217

Merged
luisdalmolin merged 5 commits intomasterfrom
issue-216
Aug 6, 2025
Merged

Add support for Laravel scope attributes in joinRelationship callbacks#217
luisdalmolin merged 5 commits intomasterfrom
issue-216

Conversation

@luisdalmolin
Copy link
Member

Summary

  • Add support for Laravel's new #[Scope] attribute syntax in joinRelationship callbacks
  • Fix issue where methods with scope attributes were not recognized by PowerJoinClause

Problem

The new Laravel scope attribute (#[\Illuminate\Database\Eloquent\Attributes\Scope]) was not working with PowerJoins when used in joinRelationship callbacks, causing the error: "Method inCountry does not exist in PowerJoinClause class".

Solution

Enhanced PowerJoinClause::__call() method to:

  • Check for Laravel scope attributes using reflection after checking traditional scopes
  • Use Laravel's callNamedScope() method for proper parameter handling
  • Maintain backward compatibility with traditional scopeMethodName syntax

Changes

  • src/PowerJoinClause.php: Added hasLaravelScopeAttribute() method and updated __call() to support scope attributes
  • tests/LaravelScopeAttributeTest.php: Added comprehensive test case reproducing the issue
  • tests/Models/: Added City, Country, CountryEnum models and updated Address model for testing
  • tests/database/migrations/: Extended migration to include countries and cities tables

Test plan

  • New test passes demonstrating scope attribute functionality
  • All existing tests (118) continue to pass - no regressions
  • Code follows project style guidelines after linting

🤖 Generated with opencode

@luisdalmolin luisdalmolin force-pushed the issue-216 branch 2 times, most recently from f7408ec to e9363a0 Compare August 6, 2025 10:31
@luisdalmolin luisdalmolin merged commit f2f8d35 into master Aug 6, 2025
38 checks passed
@luisdalmolin luisdalmolin deleted the issue-216 branch August 6, 2025 10:46
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.

1 participant