From 20ebb7e4a4e2399f3773d0d6d9247d94c4c4c00f Mon Sep 17 00:00:00 2001 From: Gitea Date: Wed, 23 Apr 2025 04:44:46 +0530 Subject: [PATCH] Added imap_setting to Setting Page --- app/Filament/Pages/Settings.php | 32 ++++++++++++++++--- app/Models/Setting.php | 4 ++- ...46_add_imap_settings_to_settings_table.php | 28 ++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2025_04_22_214146_add_imap_settings_to_settings_table.php diff --git a/app/Filament/Pages/Settings.php b/app/Filament/Pages/Settings.php index 85a706a..c44fd78 100644 --- a/app/Filament/Pages/Settings.php +++ b/app/Filament/Pages/Settings.php @@ -4,9 +4,11 @@ namespace App\Filament\Pages; use App\Models\Setting; use Filament\Actions\Action; +use Filament\Forms\Components\Checkbox; use Filament\Forms\Components\KeyValue; use Filament\Forms\Components\Repeater; use Filament\Forms\Components\Section; +use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Filament\Forms\Concerns\InteractsWithForms; @@ -34,6 +36,7 @@ class Settings extends Page implements HasForms $setting = Setting::where('app_admin', $auth_email)->first(); if ($setting) { + $imapSettings = $setting->imap_settings ?? []; $this->form->fill([ 'app_name' => $setting->app_name, 'app_version' => $setting->app_version, @@ -46,7 +49,8 @@ class Settings extends Page implements HasForms 'app_meta' => $setting->app_meta, 'app_social' => $setting->app_social, 'app_header' => $setting->app_header, - 'app_footer' => $setting->app_footer + 'app_footer' => $setting->app_footer, + 'imap_settings' => $imapSettings, ]); @@ -55,7 +59,7 @@ class Settings extends Page implements HasForms 'app_admin' => $auth_email, 'app_social' => [ null => null, - ] + ], ]); } } @@ -64,7 +68,7 @@ class Settings extends Page implements HasForms { return $form ->schema([ - Section::make('Website Infomation') + Section::make('Website Information') ->description('Change Basic Website Information') ->collapsible() ->schema([ @@ -108,6 +112,25 @@ class Settings extends Page implements HasForms ]) ]), + + Section::make('Imap') + ->description('Enter your imap server') + ->collapsed() + ->schema([ + TextInput::make('imap_settings.hostname')->label('Hostname')->required(), + TextInput::make('imap_settings.port')->label('Port')->required(), + Select::make('imap_settings.encryption')->options([ + 'none' => 'None', + 'ssl' => 'SSL', + 'tls' => 'TLS' + ]), + Checkbox::make('imap_settings.validate_cert')->label('Validate Encryption Certificate')->default(false), + TextInput::make('imap_settings.username')->label('Username')->required(), + TextInput::make('imap_settings.password')->label('Password')->required(), + TextInput::make('imap_settings.default_account')->label('Default Account')->default('default')->placeholder('default'), + TextInput::make('imap_settings.protocol')->label('Protocol')->default('imap')->placeholder('imap'), + Checkbox::make('imap_settings.cc_check')->label('Check CC Field')->default(false)->helperText('If enabled, we will check the CC field as well while fetching mails.'), + ]) ]) ->statePath('data'); } @@ -159,6 +182,7 @@ class Settings extends Page implements HasForms 'app_description' => $data['app_description'], 'app_keyword' => $data['app_keyword'], 'app_social' => $data['app_social'], + 'imap_settings' => $data['imap_settings'], ]; $create_res = Setting::create(array_merge($data)); @@ -171,7 +195,7 @@ class Settings extends Page implements HasForms } } catch (\Exception $exception) { Notification::make() - ->title('Something went wrong') + ->title('Something went wrong '.$exception->getMessage()) ->danger() ->send(); } diff --git a/app/Models/Setting.php b/app/Models/Setting.php index a079bdf..459e0a4 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -24,10 +24,12 @@ class Setting extends Model 'app_social', 'app_header', 'app_footer', + 'imap_settings', ]; protected $casts = [ 'app_meta' => 'json', - 'app_social' => 'json' + 'app_social' => 'json', + 'imap_settings' => 'json', ]; } diff --git a/database/migrations/2025_04_22_214146_add_imap_settings_to_settings_table.php b/database/migrations/2025_04_22_214146_add_imap_settings_to_settings_table.php new file mode 100644 index 0000000..68f9345 --- /dev/null +++ b/database/migrations/2025_04_22_214146_add_imap_settings_to_settings_table.php @@ -0,0 +1,28 @@ +json('imap_settings')->default('[]')->after('app_footer'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('settings', function (Blueprint $table) { + $table->dropColumn('imap_settings'); + }); + } +};