Skip to content

Commit a16b034

Browse files
Implement general settings page and migrate old settings
1 parent f85e912 commit a16b034

File tree

14 files changed

+261
-64
lines changed

14 files changed

+261
-64
lines changed

app/Facades/SiteSettings.php

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace App\Filament\Admin\Pages;
4+
5+
use App\Settings\GeneralSettings;
6+
use Filament\Forms;
7+
use Filament\Forms\Form;
8+
use Filament\Pages\SettingsPage;
9+
10+
class ManageGeneralSettings extends SettingsPage
11+
{
12+
protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';
13+
14+
protected static string $settings = GeneralSettings::class;
15+
16+
protected static ?string $navigationGroup = 'Settings';
17+
18+
protected static ?string $title = 'General Settings';
19+
20+
protected static ?string $navigationLabel = 'General Settings';
21+
22+
public function form(Form $form): Form
23+
{
24+
return $form
25+
->schema([
26+
Forms\Components\Section::make('Site Information')
27+
->schema([
28+
Forms\Components\TextInput::make('site_name')
29+
->label('Site Name')
30+
->required()
31+
->maxLength(255),
32+
Forms\Components\TextInput::make('site_email')
33+
->label('Site Email')
34+
->email()
35+
->required()
36+
->maxLength(255),
37+
Forms\Components\TextInput::make('site_phone')
38+
->label('Site Phone')
39+
->tel()
40+
->maxLength(255),
41+
Forms\Components\TextInput::make('site_address')
42+
->label('Site Address')
43+
->maxLength(255),
44+
Forms\Components\TextInput::make('site_country')
45+
->label('Country')
46+
->maxLength(255),
47+
Forms\Components\TextInput::make('site_currency')
48+
->label('Currency Symbol')
49+
->maxLength(10),
50+
Forms\Components\TextInput::make('site_default_language')
51+
->label('Default Language')
52+
->maxLength(10)
53+
->default('en'),
54+
])
55+
->columns(2),
56+
57+
Forms\Components\Section::make('Social Media Links')
58+
->description('Add your social media profile URLs')
59+
->schema([
60+
Forms\Components\TextInput::make('facebook_url')
61+
->label('Facebook URL')
62+
->url()
63+
->maxLength(255),
64+
Forms\Components\TextInput::make('twitter_url')
65+
->label('Twitter URL')
66+
->url()
67+
->maxLength(255),
68+
Forms\Components\TextInput::make('github_url')
69+
->label('GitHub URL')
70+
->url()
71+
->maxLength(255),
72+
Forms\Components\TextInput::make('youtube_url')
73+
->label('YouTube URL')
74+
->url()
75+
->maxLength(255),
76+
])
77+
->columns(2),
78+
79+
Forms\Components\Section::make('Footer')
80+
->schema([
81+
Forms\Components\Textarea::make('footer_copyright')
82+
->label('Copyright Text')
83+
->required()
84+
->maxLength(500)
85+
->rows(2),
86+
]),
87+
]);
88+
}
89+
}

app/Filament/App/Widgets/SocialLinksWidget.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,50 @@
55
use Override;
66
use Illuminate\Contracts\View\View;
77
use Filament\Widgets\Widget;
8+
use App\Settings\GeneralSettings;
89

910
class SocialLinksWidget extends Widget
1011
{
1112
protected string $view = 'filament.app.widgets.social-links-widget';
1213

13-
#[Override]
14-
public function render(): View
14+
#[Override]
15+
public function render(): View
1516
{
16-
return view($this->view, [
17-
'links' => [
17+
$settings = app(GeneralSettings::class);
18+
19+
$links = [];
20+
21+
if ($settings->github_url) {
22+
$links['GitHub'] = $settings->github_url;
23+
}
24+
25+
if ($settings->facebook_url) {
26+
$links['Facebook'] = $settings->facebook_url;
27+
}
28+
29+
if ($settings->twitter_url) {
30+
$links['Twitter'] = $settings->twitter_url;
31+
}
32+
33+
if ($settings->youtube_url) {
34+
$links['YouTube'] = $settings->youtube_url;
35+
}
36+
37+
// Keep the Facebook Groups as fallback
38+
if (empty($links)) {
39+
$links = [
1840
'GitHub' => 'https://www.github.com/liberu-genealogy',
1941
'Facebook Page' => 'https://www.facebook.com/familytree365',
2042
'Facebook Groups' => [
2143
'Family Tree 365' => 'https://www.facebook.com/groups/familytree365',
2244
'Genealogy Chat' => 'https://www.facebook.com/groups/genealogychat',
2345
'DNA 365' => 'https://www.facebook.com/groups/dna365',
2446
],
25-
],
47+
];
48+
}
49+
50+
return view($this->view, [
51+
'links' => $links,
2652
]);
2753
}
2854
}

app/Providers/Filament/AdminPanelProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function panel(Panel $panel): Panel
4141
->passwordReset()
4242
->emailVerification()
4343
->viteTheme('resources/css/filament/admin/theme.css')
44+
->brandName(fn () => app(\App\Settings\GeneralSettings::class)->site_name)
4445
->colors([
4546
'primary' => Color::Gray,
4647
])

app/Providers/Filament/AppPanelProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function panel(Panel $panel): Panel
5151
'primary' => Color::Emerald,
5252
'gray' => Color::Slate,
5353
])
54-
->brandName('Liberu Genealogy')
54+
->brandName(fn () => app(\App\Settings\GeneralSettings::class)->site_name)
5555
->brandLogo(asset('images/logo.svg'))
5656
->favicon(asset('images/favicon.ico'))
5757
/** ->navigationGroups([

app/Providers/SiteSettingsServiceProvider.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

app/Settings/GeneralSettings.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Settings;
4+
5+
use Spatie\LaravelSettings\Settings;
6+
7+
class GeneralSettings extends Settings
8+
{
9+
public string $site_name;
10+
public string $site_email;
11+
public string $site_phone;
12+
public string $site_address;
13+
public string $site_country;
14+
public string $site_currency;
15+
public string $site_default_language;
16+
17+
// Social Media Links
18+
public ?string $facebook_url;
19+
public ?string $twitter_url;
20+
public ?string $github_url;
21+
public ?string $youtube_url;
22+
23+
// Footer Copyright
24+
public string $footer_copyright;
25+
26+
public static function group(): string
27+
{
28+
return 'general';
29+
}
30+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Spatie\LaravelSettings\Migrations\SettingsMigration;
4+
5+
return new class extends SettingsMigration
6+
{
7+
public function up(): void
8+
{
9+
$this->migrator->add('general.site_name', config('app.name', 'Liberu Genealogy'));
10+
$this->migrator->add('general.site_email', 'info@example.com');
11+
$this->migrator->add('general.site_phone', '');
12+
$this->migrator->add('general.site_address', '');
13+
$this->migrator->add('general.site_country', '');
14+
$this->migrator->add('general.site_currency', '$');
15+
$this->migrator->add('general.site_default_language', 'en');
16+
$this->migrator->add('general.facebook_url', null);
17+
$this->migrator->add('general.twitter_url', null);
18+
$this->migrator->add('general.github_url', 'https://www.github.com/liberu-genealogy');
19+
$this->migrator->add('general.youtube_url', null);
20+
$this->migrator->add('general.footer_copyright', '© ' . date('Y') . ' ' . config('app.name', 'Liberu Genealogy') . '. All rights reserved.');
21+
}
22+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Support\Facades\DB;
5+
6+
return new class extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*/
11+
public function up(): void
12+
{
13+
// Migrate data from old site_settings table to new settings table
14+
$oldSettings = DB::table('site_settings')->first();
15+
16+
if ($oldSettings) {
17+
$settingsData = [
18+
['group' => 'general', 'name' => 'site_name', 'payload' => json_encode($oldSettings->name ?? config('app.name', 'Liberu Genealogy')), 'locked' => 0],
19+
['group' => 'general', 'name' => 'site_email', 'payload' => json_encode($oldSettings->email ?? 'info@example.com'), 'locked' => 0],
20+
['group' => 'general', 'name' => 'site_phone', 'payload' => json_encode($oldSettings->phone_01 ?? ''), 'locked' => 0],
21+
['group' => 'general', 'name' => 'site_address', 'payload' => json_encode($oldSettings->address ?? ''), 'locked' => 0],
22+
['group' => 'general', 'name' => 'site_country', 'payload' => json_encode($oldSettings->country ?? ''), 'locked' => 0],
23+
['group' => 'general', 'name' => 'site_currency', 'payload' => json_encode($oldSettings->currency ?? '$'), 'locked' => 0],
24+
['group' => 'general', 'name' => 'site_default_language', 'payload' => json_encode($oldSettings->default_language ?? 'en'), 'locked' => 0],
25+
['group' => 'general', 'name' => 'facebook_url', 'payload' => json_encode($oldSettings->facebook), 'locked' => 0],
26+
['group' => 'general', 'name' => 'twitter_url', 'payload' => json_encode($oldSettings->twitter), 'locked' => 0],
27+
['group' => 'general', 'name' => 'github_url', 'payload' => json_encode($oldSettings->github ?? 'https://www.github.com/liberu-genealogy'), 'locked' => 0],
28+
['group' => 'general', 'name' => 'youtube_url', 'payload' => json_encode($oldSettings->youtube), 'locked' => 0],
29+
['group' => 'general', 'name' => 'footer_copyright', 'payload' => json_encode('© ' . date('Y') . ' ' . ($oldSettings->name ?? config('app.name', 'Liberu Genealogy')) . '. All rights reserved.'), 'locked' => 0],
30+
];
31+
32+
foreach ($settingsData as $setting) {
33+
DB::table('settings')->updateOrInsert(
34+
['group' => $setting['group'], 'name' => $setting['name']],
35+
$setting
36+
);
37+
}
38+
}
39+
}
40+
41+
/**
42+
* Reverse the migrations.
43+
*/
44+
public function down(): void
45+
{
46+
// Remove the migrated settings
47+
DB::table('settings')->where('group', 'general')->delete();
48+
}
49+
};

database/seeders/SiteSettingsSeeder.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@
33
namespace Database\Seeders;
44

55
use Illuminate\Database\Seeder;
6-
use App\Models\SiteSettings;
6+
use App\Settings\GeneralSettings;
77

88
class SiteSettingsSeeder extends Seeder
99
{
1010
public function run()
1111
{
12-
SiteSettings::create([
13-
'name' => config('app.name', 'Liberu Real Estate'),
14-
'currency' => '£',
15-
'default_language' => 'en',
16-
'address' => '123 Real Estate St, London, UK',
17-
'country' => 'United Kingdom',
18-
'email' => 'info@liberurealestate.com',
19-
]);
12+
$settings = app(GeneralSettings::class);
13+
14+
$settings->site_name = config('app.name', 'Liberu Genealogy');
15+
$settings->site_email = 'info@liberugenealogy.com';
16+
$settings->site_phone = '+44 208 050 5865';
17+
$settings->site_address = '123 Genealogy St, London, UK';
18+
$settings->site_country = 'United Kingdom';
19+
$settings->site_currency = '£';
20+
$settings->site_default_language = 'en';
21+
$settings->facebook_url = 'https://www.facebook.com/familytree365';
22+
$settings->twitter_url = null;
23+
$settings->github_url = 'https://www.github.com/liberu-genealogy';
24+
$settings->youtube_url = null;
25+
$settings->footer_copyright = '© ' . date('Y') . ' ' . config('app.name', 'Liberu Genealogy') . '. All rights reserved.';
26+
27+
$settings->save();
2028
}
21-
}
29+
}

0 commit comments

Comments
 (0)