diff --git a/app/Filament/Pages/Settings.php b/app/Filament/Pages/Settings.php new file mode 100644 index 0000000..85a706a --- /dev/null +++ b/app/Filament/Pages/Settings.php @@ -0,0 +1,179 @@ +user(); + $auth_email = $user->email; + $setting = Setting::where('app_admin', $auth_email)->first(); + + if ($setting) { + $this->form->fill([ + 'app_name' => $setting->app_name, + 'app_version' => $setting->app_version, + 'app_base_url' => $setting->app_base_url, + 'app_admin' => $setting->app_admin, + 'app_contact' => $setting->app_contact, + 'app_title' => $setting->app_title, + 'app_description' => $setting->app_description, + 'app_keyword' => $setting->app_keyword, + 'app_meta' => $setting->app_meta, + 'app_social' => $setting->app_social, + 'app_header' => $setting->app_header, + 'app_footer' => $setting->app_footer + ]); + + + } else { + $this->form->fill([ + 'app_admin' => $auth_email, + 'app_social' => [ + null => null, + ] + ]); + } + } + + public function form(Form $form): Form + { + return $form + ->schema([ + Section::make('Website Infomation') + ->description('Change Basic Website Information') + ->collapsible() + ->schema([ + TextInput::make('app_name')->label('Website Name')->required(), + TextInput::make('app_version')->label('Website Version')->required(), + TextInput::make('app_base_url')->label('Base URL')->required(), + TextInput::make('app_admin')->label('Website Admin')->email()->required(), + TextInput::make('app_contact')->label('Contact Email')->email()->required(), + ]), + Section::make('Custom Codes') + ->description('Add custom codes to header and footer') + ->collapsed() + ->columns(2) + ->schema([ + Textarea::make('app_header')->label('Custom Header')->rows(6)->columnSpan(1), + Textarea::make('app_footer')->label('Custom Footer')->rows(6)->columnSpan(1), + ]), + Section::make('Meta Information') + ->description('Change Website Meta Information') + ->collapsed() + ->schema([ + TextInput::make('app_title')->label('Title')->required(), + Textarea::make('app_description')->label('Description')->rows(3), + TextInput::make('app_keyword')->label('Keyword'), + KeyValue::make('app_meta') + ->label('Meta (Optional)') + ->keyPlaceholder('Name') + ->valuePlaceholder('Content'), + ]), + Section::make('Social Links') + ->description('Enter your social links') + ->collapsed() + ->schema([ + + + Repeater::make('app_social') + ->statePath('app_social') + ->schema([ + TextInput::make('icon')->label('Icon')->required()->maxLength(100), + TextInput::make('url')->label('URL')->url()->required()->maxLength(255), + ]) + + ]), + ]) + ->statePath('data'); + } + + protected function getFormActions(): array + { + return [ + Action::make('save') + ->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label')) + ->submit('save'), + ]; + } + + public function save(): void + { + try { + + $data = $this->form->getState(); + $setting = Setting::where('id', 1)->first(); + + $user = auth()->user(); + $auth_email = $user->email; + + if ($setting) { + $app_admin = $setting->app_admin; + if ($app_admin == $auth_email) { + $update_res = $setting->update($data); + if($update_res) { + Notification::make() + ->title('Saved successfully') + ->success() + ->send(); + } + } else { + Notification::make() + ->title('Please Login With Administrator Credentials') + ->danger() + ->send(); + } + } else { + $data = [ + 'id' => 1, + 'app_name' => $data['app_name'], + 'app_version' => $data['app_version'], + 'app_base_url' => $data['app_base_url'], + 'app_admin' => $auth_email, + 'app_contact' => $data['app_contact'], + 'app_title' => $data['app_title'], + 'app_description' => $data['app_description'], + 'app_keyword' => $data['app_keyword'], + 'app_social' => $data['app_social'], + ]; + $create_res = Setting::create(array_merge($data)); + + if($create_res) { + Notification::make() + ->title('Saved successfully') + ->success() + ->send(); + } + } + } catch (\Exception $exception) { + Notification::make() + ->title('Something went wrong') + ->danger() + ->send(); + } + } +} diff --git a/app/Models/Setting.php b/app/Models/Setting.php new file mode 100644 index 0000000..a079bdf --- /dev/null +++ b/app/Models/Setting.php @@ -0,0 +1,33 @@ + 'json', + 'app_social' => 'json' + ]; +} diff --git a/database/migrations/2025_04_22_210144_create_settings_table.php b/database/migrations/2025_04_22_210144_create_settings_table.php new file mode 100644 index 0000000..9fa1efe --- /dev/null +++ b/database/migrations/2025_04_22_210144_create_settings_table.php @@ -0,0 +1,39 @@ +id(); + $table->string('app_name'); + $table->string('app_version')->default('1.0'); + $table->string('app_base_url')->url(); + $table->string('app_admin'); + $table->string('app_title'); + $table->longText('app_description')->nullable(); + $table->longText('app_keyword')->nullable(); + $table->string('app_contact')->email()->nullable(); + $table->longText('app_meta')->default('[]')->nullable(); + $table->longText('app_social')->default('[]')->nullable(); + $table->longText('app_header')->nullable(); + $table->longText('app_footer')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('settings'); + } +}; diff --git a/resources/views/filament/pages/settings.blade.php b/resources/views/filament/pages/settings.blade.php new file mode 100644 index 0000000..14f565e --- /dev/null +++ b/resources/views/filament/pages/settings.blade.php @@ -0,0 +1,15 @@ + + @auth + @if (auth()->user()->level === 9) + @livewire('notifications') + + {{ $this->form }} + + + @else + @php abort(403); @endphp + @endif + @endauth +