Skip to content

Commit

Permalink
Email template themes > 'is_default' flag management, only one can be…
Browse files Browse the repository at this point in the history
… default
  • Loading branch information
akshaybokaderanium committed Sep 12, 2023
1 parent a55b9bd commit 2f65554
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Visualbuilder\EmailTemplates\Resources\EmailTemplateThemeResource;
use Illuminate\Database\Eloquent\Model;
use Visualbuilder\EmailTemplates\Models\EmailTemplateTheme;

class EditEmailTemplateTheme extends EditRecord
{
Expand All @@ -16,4 +18,16 @@ protected function getHeaderActions(): array
Actions\DeleteAction::make(),
];
}

protected function handleRecordUpdate(Model $record, array $data): Model
{
$record->update($data);

if($data['is_default']) {
EmailTemplateTheme::where('id', '!=', $record->id)
->where('is_default', true)
->update(['is_default' => false]);
}
return $record;
}
}

0 comments on commit 2f65554

Please sign in to comment.