Allows to use Relation instead of Builder to generate data #279
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During my development using this awesome package, I needed to display a table taking data from a many to many relationship:
Course <=> Subscription <=> Student
in order to render a table to display all students of a specific course, I used laravel-livewire-tables and tried to take data this way
I thought everything worked until I tried to take one of the row's ID and found that it was not the ID of the Student, but the ID of the pivot table (Subscription)
that's because getQuery() of a many to many relationship mixes columns of both tables
an elegant solution would be to return an
Illuminate\Database\Eloquent\Relations\Relation
instead of the Builder:but this is not possible because of the strict return type checking of the query() method's signature
this PR slightly changes the code in order to loose the strict type checking, allowing to return a Relation.
every test runs smoothly without any change and this is a non breaking change: removing typechecking from parent method allows to still use typechecking on the classes extending it.
I could not use union types because of the php7.4 requirement, maybe this would be a nice additional PR in a future version as the php7.4 requirement will be dropped
@rappasoft sorry for my english, I'm not a native speaker. I hope to have well explained my goal with this pull request
and thanks for you awesome work! You saved me a lot of code!
edit: added tests