Run function while creating record not on editing.
Hi everyone, I'm working on a Filament project, specifically in the MovieManagementResource, and I want to run the generateDateSchedules method only when creating a new movie. I am trying to use request()->routeIs('filament.admin.resources.movie-managements.create') in the afterStateUpdated callback of the DatePicker, but it doesn't seem to be working. Here’s part of my code:
Forms\Components\DatePicker::make('release_date')
->required()
->reactive()
->afterStateUpdated(function (Set $set, Get $get, $state) {
if (request()->routeIs('filament.admin.resources.movie-managements.create')) {
$releaseDate = Carbon::parse($state);
$endDate = Carbon::parse($get('end_date'));
if ($endDate) {
self::generateDateSchedules($set, $releaseDate, $endDate);
}
}
});
Solution:Jump to solution
Try operation:
```php
->afterStateUpdated(function (Set $set, Get $get, $state, string $operation) {
if ($operation == 'create') {
dd($operation);...
3 Replies
Solution
Try operation:
Than you very much sir.