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

Trait Method Collision Error #19

Open
ZayRTun opened this issue Jul 10, 2024 · 3 comments
Open

Trait Method Collision Error #19

ZayRTun opened this issue Jul 10, 2024 · 3 comments

Comments

@ZayRTun
Copy link

ZayRTun commented Jul 10, 2024

Description:
After adding the traits to all the resource pages I am getting the following error.

Note: It's happening because of Filament Translatable plugin.

Trait method Guava\FilamentDrafts\Admin\Resources\Pages\Create\Draftable::handleRecordCreation has not been applied as App\Filament\Resources\DeveloperResource\Pages\CreateDeveloper::handleRecordCreation, because of collision with Filament\Resources\Pages\CreateRecord\Concerns\Translatable::handleRecordCreation

Environment:

  • PHP version: 8.2
  • Laravel version: 11.14
  • Filament version: 3.2

Possible Solution:
To resolve the collision, consider renaming one of the conflicting methods..

Screenshot 2024-07-10 at 09 57 51

@dave-mills
Copy link

I've just come across almost this exact issue, while trying to add this package to an app that uses Translatable. The issue is that both traits are attempting to overwrite the base handleRecordCreation() method from the CreateRecord class, so renaming the method won't work. Short term, options are:

  1. create your own handleRecordCreation() method that does the things you want from both traits; (probably the best approach for a single use-case).
  2. see if there's a different approach to using the underlying OddType\Draftable package without changing handleRecordCreation().

I wonder if, long term, the idea of overwriting the handleRecordCreation method to modify how records are saved with traits isn't the best approach for either package.

@lukas-frey
Copy link
Contributor

lukas-frey commented Sep 18, 2024

A possible fix would be to provide our own Translatable implementation just like we do in Nested Resources, but then if these two packages would be used together, a collision will still happen.

For now, do as @dave-mills suggests. You can also "override" the name of a trait method:

use Translatable {
    Translatable::handleRecordCreation as filamentHandleRecordCreation;
}

and then you can call the `filamentHandleRecordCreation` method in your code if and when needed.

@dave-mills
Copy link

Thanks @lukas-frey for the idea of overriding the trait names. That's instantly tidied up my mess of a function!

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

No branches or pull requests

3 participants