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

feat: laravel 8/9/10 support #13

Closed
wants to merge 4 commits into from

Conversation

audunru
Copy link

@audunru audunru commented Dec 26, 2023

BREAKING CHANGE: Support for Laravel 8/9/10. Drops support for Laravel 5/6/7.

Based on ajcastro's PR to laravel/framework which was not accepted, sadly.

In this PR we override the newBelongsToMany() method of Laravel's HasRelationships trait and replace the BelongsToMany class with our own version with support for eager loading pivot relations.

Overriding BelongsToMany's get() method is not exactly the cleanest solution, but it allows us to tack on support only for BelongsToMany relationships and gives access to the $accessor property in a clean fashion. In the previous version, some code was dedicated to discovering the relationship model's $accessor value from the query builder. IMO this is easier to understand, so I understand the original author's decision to go that way. The downside is some duplication of framework code in the overriden get() method now that we have to do this outside of the framework itself.

I suggest that in the future, in order to support newer versions of Laravel, backwards compatibility is dropped in favor of a potentially cleaner solution if we find one.

Thank you for the actual work on this @ajcastro :-)

Minimum PHP version bumped to 7.3 to match Laravel 8's minimum. orchestra/testbench bumped to v6 to match Laravel 8.

Tested with a Laravel 10 application on PHP 8.2.

Close #8
Close #12

BREAKING CHANGE: Support for Laravel 8/9/10 based on @ajcastro PR to laravel/framework which was not accepted, sadly.
@ricardoaranha96
Copy link

@audunru would you consider publish it as a new package if the PR doesn't get approved? There's been a while since the last commit done by @ajcastro For now, I coppied your code to my project in order to use it. You saved me.

@audunru
Copy link
Author

audunru commented Jan 6, 2024

That's a possibility. I'm currently referencing my forked repo in my composer.json just to get it working, but a published package would be preferrable. Hopefully we can get it merged.

@audunru audunru closed this Jan 12, 2024
@audunru
Copy link
Author

audunru commented Jan 12, 2024

@ricardoaranha96 Will publish this as a new package

@ricardoaranha96
Copy link

@audunru Thank you very much

@ryanmortier
Copy link

@audunru Thank you for maintaining your fork. It's working great for me.

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.

[Support] Laravel 9 Laravel 8 Support
4 participants