xxxxxxxxxx
class YourResource extends Resource
{
// Your resource configuration...
public function form(Form $form)
{
// Determine if it's a create or save action
$isCreateAction = is_null($form->getModel()->getKey());
// Use $isCreateAction to customize the form behavior
if ($isCreateAction) {
// Perform actions specific to create
} else {
// Perform actions specific to save
}
// Add form fields...
}
}
use Filament\Resources\Forms\Form;
use Filament\Resources\Forms\Components\TextInput;
Form::make()
->schema([
TextInput::make('name')->required(),
// other fields...
])
->saving(function ($state) {
if ($this->getModel()->exists) {
// This is an update operation
} else {
// This is a create operation
}
});