filament-drafts
filament-drafts copied to clipboard
Trait Method Collision Error
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..
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:
- create your own
handleRecordCreation()method that does the things you want from both traits; (probably the best approach for a single use-case). - 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.
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.
Thanks @lukas-frey for the idea of overriding the trait names. That's instantly tidied up my mess of a function!