-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Trait collision: Conflict with other traits overriding newCollection method #287
Comments
Hi @yusrashahina, Are you using the collection's methods use Plank\Mediable\Mediable;
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;
class Category extends Model {
use Mediable, HasRecursiveRelationships {
Mediable::newCollection insteadof HasRecursiveRelationships;
}
} |
Hi @staudenmeir, I do use Is there a way to retain both Our current workaround (custom |
In this case, you do need to merge both
What does your current |
Here’s our current
Methods like |
Have you tried this approach? namespace App\Collections;
use Plank\Mediable\MediableCollection;
class HybridCollection extends MediableCollection
{
public function toTree()
{
// TODO: Copy code from Staudenmeir\LaravelAdjacencyList\Eloquent\Collection
}
} |
When using
HasRecursiveRelationships
alongside traits that overridenewCollection
(e.g.,Mediable
fromplank/mediable
), a fatal error occurs due to method collision:Trait method 'newCollection' will not be applied because it collides with another trait method.
Steps to Reproduce:
composer require plank/mediable staudenmeir/laravel-adjacency-list
Create a model using both traits:
Attempt to use the model (e.g., fetch records).
Trait method 'newCollection' has not been applied because there are collisions with other trait methods on App\Models\Category
Temporary Workaround:
A custom collection class can be created to combine both traits’ collection logic, but this requires manual delegation (example below). However, this may not cover all edge cases.
Request:
Could the package provide a way to avoid overriding
newCollection
or make it compatible with other traits that modify collections? For example:newCollection
override.newCollection
method (e.g., splitHasAdjacencyList
into subtraits).Example Workaround Code:
Thank you for this excellent package! Any guidance or updates to resolve this would be appreciated.
The text was updated successfully, but these errors were encountered: