Skip to content

Commit 22ae702

Browse files
authored
Added public dashboard enabled setting to general settings (alexjustesen#856)
1 parent 91a4547 commit 22ae702

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

app/Filament/Pages/Settings/GeneralPage.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ public function form(Form $form): Form
114114
'default' => 1,
115115
'md' => 2,
116116
]),
117+
118+
Forms\Components\Section::make('Public Dashboard Settings')
119+
->schema([
120+
Forms\Components\Toggle::make('public_dashboard_enabled')
121+
->label('Enable')
122+
->columnSpan(2),
123+
])
124+
->compact()
125+
->columns([
126+
'default' => 1,
127+
'md' => 2,
128+
]),
117129
])
118130
->columnSpan('full'),
119131
]);

app/Http/Controllers/HomeController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers;
44

55
use App\Models\Result;
6+
use App\Settings\GeneralSettings;
67
use Illuminate\Http\Request;
78

89
class HomeController extends Controller
@@ -12,6 +13,11 @@ class HomeController extends Controller
1213
*/
1314
public function __invoke(Request $request)
1415
{
16+
$settings = new GeneralSettings();
17+
if (!$settings->public_dashboard_enabled) {
18+
return redirect()->route('filament.admin.auth.login');
19+
}
20+
1521
$latestResult = Result::query()
1622
->select(['id', 'ping', 'download', 'upload', 'successful', 'created_at'])
1723
->latest()

app/Settings/GeneralSettings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class GeneralSettings extends Settings
1919

2020
public string $timezone;
2121

22+
public bool $public_dashboard_enabled;
23+
2224
public static function group(): string
2325
{
2426
return 'general';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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.public_dashboard_enabled', true);
10+
}
11+
};

0 commit comments

Comments
 (0)