Access handleRecordCreation on resource

I have a create class in one of my resources, within this resource i use the handleRecordCreation() However i want to access this method when doing a form action for a resource manager.
->headerActions([
Tables\Actions\CreateAction::make()
->using(function (array $data, RelationManager $livewire) {
//...
}),
])
->headerActions([
Tables\Actions\CreateAction::make()
->using(function (array $data, RelationManager $livewire) {
//...
}),
])
This is in the table actions of my tables
class CreateAgreement extends CreateRecord
{
protected static string $resource = AgreementResource::class;

protected function handleRecordCreation(array $data): Model
{
// ..
}
}
class CreateAgreement extends CreateRecord
{
protected static string $resource = AgreementResource::class;

protected function handleRecordCreation(array $data): Model
{
// ..
}
}
Rather than duplicate, or create a laravel action class or similar, is there a desired "filament way" to use the logic from handleRecordCreation() from within the using() method on table actions.
4 Replies
Patrick Boivin
Patrick Boivinβ€’15mo ago
I usually extract this to an "action class". Not a Filament Action, but just a generic class that can perform something :
use App\Actions\CreateAgreement;

protected function handleRecordCreation(array $data): Model
{
CreateAgreement::run($data);
}
use App\Actions\CreateAgreement;

protected function handleRecordCreation(array $data): Model
{
CreateAgreement::run($data);
}
Patrick Boivin
Patrick Boivinβ€’15mo ago
Could be a plain PHP class or if you want to dig much deeper, I really like this package: https://github.com/lorisleiva/laravel-actions
GitHub
GitHub - lorisleiva/laravel-actions: ⚑️ Laravel components that tak...
⚑️ Laravel components that take care of one specific task - GitHub - lorisleiva/laravel-actions: ⚑️ Laravel components that take care of one specific task
Patrick Boivin
Patrick Boivinβ€’15mo ago
or create a laravel action class or similar,
Ok, I missed this part of your message But my suggestion still stands πŸ˜„
Aaron Lawrence
Aaron LawrenceOPβ€’15mo ago
Okay, this is nice to know though, it kind of means I'm not heading in a wrong direction πŸ˜” I really appreciate the feedback I guess that's what I'll do πŸ˜ƒ
Want results from more Discord servers?
Add your server