Level 58
Certainly! In Filament's RelationManager, the afterCreate() method is not called automatically after a record is created. Instead, you should override the afterCreate() hook on the form returned by the form() method.
Here's how you can do it:
use Filament\Forms;
class UnitsRelationManager extends RelationManager
{
protected static string $relationship = 'units';
protected static ?string $recordTitleAttribute = 'reference';
public function isReadOnly(): bool
{
return false;
}
public static function form(Forms\Form $form): Forms\Form
{
return $form
->schema([
// ... your form fields here
])
->afterCreate(function (Model $record) {
dd('here');
});
}
}
Key Points:
- The
afterCreate()hook should be chained on the form instance, not as a protected method of the class. - The closure receives the newly created
$record.
References:
Let me know if you need a more detailed example!