check if AsPivot trait is used instead of Pivot Model #35271
Merged
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.
Right now the logic that allows using a class name of a pivot model as
$table
argument and resolves its table and also uses it as pivot model only checks for the default\Illuminate\Database\Eloquent\Relations\Pivot
model class.The problem with this is that the real thing that makes a pivot model is the
\Illuminate\Database\Eloquent\Relations\Concerns\AsPivot
trait.This PR changes this condition to check for the trait instead of an instance check for the base class.
The benefit is that the user is able to create his own pivot base model that doesn't have to be based on the default pivot model.
As an example - that's our custom pivot model in one app that's based on our custom base model.