Hello Mika,
In Filament, you can use the afterSave callback to perform actions after the form has been saved. You've already added the afterSave method to your CreateBanner class, which is the right approach. However, you need to ensure that you're passing the callback correctly to the afterSave method in the form definition.
Here's how you can modify your CreateBanner class to get the saved model's ID:
use Filament\Resources\Form;
use Filament\Resources\Pages\CreateRecord;
class CreateBanner extends CreateRecord
{
public static function form(Form $form): Form
{
return $form
->schema([
// all form code here
])
->afterSave(function ($record) {
$savedModelId = $record->id;
dd($savedModelId);
});
}
}
In this code, the afterSave method is passed as a closure to the afterSave method of the form. This closure receives the $record parameter, which is the instance of the model that has just been saved. You can then access the id property of the $record to get the saved model's ID.
Make sure that you're using the correct namespace for the Form and CreateRecord classes if they are located in a different namespace in your application.
I hope this helps you get the saved model's ID in Filament. If you have any further questions, feel free to ask!