feat: implement general settings management using Spatie Laravel Settings and Filament.

This commit is contained in:
Yoga Pangestu 2026-03-11 22:16:15 +07:00
parent 6d1ce9cdf6
commit 2019928fb3
6 changed files with 475 additions and 24 deletions

View File

@ -0,0 +1,64 @@
<?php
namespace App\Filament\Pages\System;
use App\Filament\Support\SystemNotification;
use App\Settings\GeneralSettings;
use BackedEnum;
use Filament\Forms\Components\Select;
use Filament\Notifications\Notification;
use Filament\Pages\SettingsPage;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use UnitEnum;
class ManageSettings extends SettingsPage
{
protected static string|UnitEnum|null $navigationGroup = 'Sistem';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCog6Tooth;
protected static ?string $title = 'Pengaturan';
protected static ?string $navigationLabel = 'Pengaturan';
protected static ?string $slug = 'system/settings';
protected static ?int $navigationSort = 10;
protected static string $settings = GeneralSettings::class;
public function form(Schema $schema): Schema
{
return $schema
->components([
Section::make()
->schema([
Select::make('current_semester')
->label('Semester Sekarang')
->placeholder('Pilih Semester')
->options([
1 => 'Semester 1',
2 => 'Semester 2',
3 => 'Semester 3',
4 => 'Semester 4',
5 => 'Semester 5',
6 => 'Semester 6',
7 => 'Semester 7',
8 => 'Semester 8',
])
->native(false)
->required()
->helperText('Tentukan semester yang sedang aktif saat ini. Semester ini akan digunakan untuk menyaring data yang relevan.'),
])
->columns(2)
->columnSpanFull(),
]);
}
public function getSavedNotification(): ?Notification
{
return SystemNotification::update();
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Settings;
use Spatie\LaravelSettings\Settings;
class GeneralSettings extends Settings
{
public int $current_semester;
public static function group(): string
{
return 'general';
}
}

View File

@ -12,6 +12,7 @@
"diogogpinto/filament-auth-ui-enhancer": "^2.0",
"filament/filament": "^5.0",
"filament/spatie-laravel-media-library-plugin": "^5.0",
"filament/spatie-laravel-settings-plugin": "^5.0",
"joaopaulolndev/filament-pdf-viewer": "^3.0",
"laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1",

384
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "fb3b39bd93675cf5a357cae91a0f35e9",
"content-hash": "8392d40ff038be5645719684849b3b88",
"packages": [
{
"name": "achyutn/filament-log-viewer",
@ -974,6 +974,54 @@
],
"time": "2026-01-18T00:13:04+00:00"
},
{
"name": "doctrine/deprecations",
"version": "1.1.6",
"source": {
"type": "git",
"url": "https://github.com/doctrine/deprecations.git",
"reference": "d4fe3e6fd9bb9e72557a19674f44d8ac7db4c6ca"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/d4fe3e6fd9bb9e72557a19674f44d8ac7db4c6ca",
"reference": "d4fe3e6fd9bb9e72557a19674f44d8ac7db4c6ca",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"conflict": {
"phpunit/phpunit": "<=7.5 || >=14"
},
"require-dev": {
"doctrine/coding-standard": "^9 || ^12 || ^14",
"phpstan/phpstan": "1.4.10 || 2.1.30",
"phpstan/phpstan-phpunit": "^1.0 || ^2",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.6 || ^10.5 || ^11.5 || ^12.4 || ^13.0",
"psr/log": "^1 || ^2 || ^3"
},
"suggest": {
"psr/log": "Allows logging deprecations via PSR-3 logger implementation"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Deprecations\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.",
"homepage": "https://www.doctrine-project.org/",
"support": {
"issues": "https://github.com/doctrine/deprecations/issues",
"source": "https://github.com/doctrine/deprecations/tree/1.1.6"
},
"time": "2026-02-07T07:09:04+00:00"
},
{
"name": "doctrine/inflector",
"version": "2.1.0",
@ -1648,6 +1696,50 @@
},
"time": "2026-02-25T15:34:28+00:00"
},
{
"name": "filament/spatie-laravel-settings-plugin",
"version": "v5.3.2",
"source": {
"type": "git",
"url": "https://github.com/filamentphp/spatie-laravel-settings-plugin.git",
"reference": "be3377b4fdf61e958106c7c143fdc5c96b2db304"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/filamentphp/spatie-laravel-settings-plugin/zipball/be3377b4fdf61e958106c7c143fdc5c96b2db304",
"reference": "be3377b4fdf61e958106c7c143fdc5c96b2db304",
"shasum": ""
},
"require": {
"filament/filament": "self.version",
"php": "^8.2",
"spatie/laravel-settings": "^3.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Filament\\SpatieLaravelSettingsPluginServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Filament\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Filament support for `spatie/laravel-settings`.",
"homepage": "https://github.com/filamentphp/filament",
"support": {
"issues": "https://github.com/filamentphp/filament/issues",
"source": "https://github.com/filamentphp/filament"
},
"time": "2026-01-29T21:01:34+00:00"
},
{
"name": "filament/support",
"version": "v5.3.2",
@ -2140,16 +2232,16 @@
},
{
"name": "guzzlehttp/psr7",
"version": "2.8.0",
"version": "2.9.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "21dc724a0583619cd1652f673303492272778051"
"reference": "7d0ed42f28e42d61352a7a79de682e5e67fec884"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/21dc724a0583619cd1652f673303492272778051",
"reference": "21dc724a0583619cd1652f673303492272778051",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/7d0ed42f28e42d61352a7a79de682e5e67fec884",
"reference": "7d0ed42f28e42d61352a7a79de682e5e67fec884",
"shasum": ""
},
"require": {
@ -2165,6 +2257,7 @@
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"http-interop/http-factory-tests": "0.9.0",
"jshttp/mime-db": "1.54.0.1",
"phpunit/phpunit": "^8.5.44 || ^9.6.25"
},
"suggest": {
@ -2236,7 +2329,7 @@
],
"support": {
"issues": "https://github.com/guzzle/psr7/issues",
"source": "https://github.com/guzzle/psr7/tree/2.8.0"
"source": "https://github.com/guzzle/psr7/tree/2.9.0"
},
"funding": [
{
@ -2252,7 +2345,7 @@
"type": "tidelift"
}
],
"time": "2025-08-23T21:21:41+00:00"
"time": "2026-03-10T16:41:02+00:00"
},
{
"name": "guzzlehttp/uri-template",
@ -2475,16 +2568,16 @@
},
{
"name": "laravel/framework",
"version": "v12.53.0",
"version": "v12.54.1",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "f57f035c0d34503d9ff30be76159bb35a003cd1f"
"reference": "325497463e7599cd14224c422c6e5dd2fe832868"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/f57f035c0d34503d9ff30be76159bb35a003cd1f",
"reference": "f57f035c0d34503d9ff30be76159bb35a003cd1f",
"url": "https://api.github.com/repos/laravel/framework/zipball/325497463e7599cd14224c422c6e5dd2fe832868",
"reference": "325497463e7599cd14224c422c6e5dd2fe832868",
"shasum": ""
},
"require": {
@ -2505,7 +2598,7 @@
"guzzlehttp/uri-template": "^1.0",
"laravel/prompts": "^0.3.0",
"laravel/serializable-closure": "^1.3|^2.0",
"league/commonmark": "^2.7",
"league/commonmark": "^2.8.1",
"league/flysystem": "^3.25.1",
"league/flysystem-local": "^3.25.1",
"league/uri": "^7.5.1",
@ -2693,20 +2786,20 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2026-02-24T14:35:15+00:00"
"time": "2026-03-10T20:25:56+00:00"
},
{
"name": "laravel/prompts",
"version": "v0.3.13",
"version": "v0.3.14",
"source": {
"type": "git",
"url": "https://github.com/laravel/prompts.git",
"reference": "ed8c466571b37e977532fb2fd3c272c784d7050d"
"reference": "9f0e371244eedfe2ebeaa72c79c54bb5df6e0176"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/prompts/zipball/ed8c466571b37e977532fb2fd3c272c784d7050d",
"reference": "ed8c466571b37e977532fb2fd3c272c784d7050d",
"url": "https://api.github.com/repos/laravel/prompts/zipball/9f0e371244eedfe2ebeaa72c79c54bb5df6e0176",
"reference": "9f0e371244eedfe2ebeaa72c79c54bb5df6e0176",
"shasum": ""
},
"require": {
@ -2750,9 +2843,9 @@
"description": "Add beautiful and user-friendly forms to your command-line applications.",
"support": {
"issues": "https://github.com/laravel/prompts/issues",
"source": "https://github.com/laravel/prompts/tree/v0.3.13"
"source": "https://github.com/laravel/prompts/tree/v0.3.14"
},
"time": "2026-02-06T12:17:10+00:00"
"time": "2026-03-01T09:02:38+00:00"
},
{
"name": "laravel/serializable-closure",
@ -3941,16 +4034,16 @@
},
{
"name": "nesbot/carbon",
"version": "3.11.1",
"version": "3.11.2",
"source": {
"type": "git",
"url": "https://github.com/CarbonPHP/carbon.git",
"reference": "f438fcc98f92babee98381d399c65336f3a3827f"
"reference": "57d696f4ec76d8560cc13b9d16ec01afc4379d04"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/CarbonPHP/carbon/zipball/f438fcc98f92babee98381d399c65336f3a3827f",
"reference": "f438fcc98f92babee98381d399c65336f3a3827f",
"url": "https://api.github.com/repos/CarbonPHP/carbon/zipball/57d696f4ec76d8560cc13b9d16ec01afc4379d04",
"reference": "57d696f4ec76d8560cc13b9d16ec01afc4379d04",
"shasum": ""
},
"require": {
@ -4042,7 +4135,7 @@
"type": "tidelift"
}
],
"time": "2026-01-29T09:26:29+00:00"
"time": "2026-03-10T21:43:48+00:00"
},
{
"name": "nette/php-generator",
@ -4654,6 +4747,117 @@
],
"time": "2026-01-20T21:26:48+00:00"
},
{
"name": "phpdocumentor/reflection-common",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionCommon.git",
"reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b",
"reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-2.x": "2.x-dev"
}
},
"autoload": {
"psr-4": {
"phpDocumentor\\Reflection\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jaap van Otterdijk",
"email": "opensource@ijaap.nl"
}
],
"description": "Common reflection classes used by phpdocumentor to reflect the code structure",
"homepage": "http://www.phpdoc.org",
"keywords": [
"FQSEN",
"phpDocumentor",
"phpdoc",
"reflection",
"static analysis"
],
"support": {
"issues": "https://github.com/phpDocumentor/ReflectionCommon/issues",
"source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x"
},
"time": "2020-06-27T09:03:43+00:00"
},
{
"name": "phpdocumentor/type-resolver",
"version": "1.12.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "92a98ada2b93d9b201a613cb5a33584dde25f195"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/92a98ada2b93d9b201a613cb5a33584dde25f195",
"reference": "92a98ada2b93d9b201a613cb5a33584dde25f195",
"shasum": ""
},
"require": {
"doctrine/deprecations": "^1.0",
"php": "^7.3 || ^8.0",
"phpdocumentor/reflection-common": "^2.0",
"phpstan/phpdoc-parser": "^1.18|^2.0"
},
"require-dev": {
"ext-tokenizer": "*",
"phpbench/phpbench": "^1.2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.1",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.13.9",
"vimeo/psalm": "^4.25"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-1.x": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"phpDocumentor\\Reflection\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mike van Riel",
"email": "me@mikevanriel.com"
}
],
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
"support": {
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.12.0"
},
"time": "2025-11-21T15:09:14+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.9.5",
@ -4729,6 +4933,53 @@
],
"time": "2025-12-27T19:41:33+00:00"
},
{
"name": "phpstan/phpdoc-parser",
"version": "2.3.2",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "a004701b11273a26cd7955a61d67a7f1e525a45a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/a004701b11273a26cd7955a61d67a7f1e525a45a",
"reference": "a004701b11273a26cd7955a61d67a7f1e525a45a",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0"
},
"require-dev": {
"doctrine/annotations": "^2.0",
"nikic/php-parser": "^5.3.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^9.6",
"symfony/process": "^5.2"
},
"type": "library",
"autoload": {
"psr-4": {
"PHPStan\\PhpDocParser\\": [
"src/"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/2.3.2"
},
"time": "2026-01-25T14:56:51+00:00"
},
{
"name": "pragmarx/google2fa",
"version": "v9.0.0",
@ -6175,6 +6426,91 @@
],
"time": "2026-02-21T12:49:54+00:00"
},
{
"name": "spatie/laravel-settings",
"version": "3.7.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-settings.git",
"reference": "83b179e8097645a30d402d75ba3c19621464494d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-settings/zipball/83b179e8097645a30d402d75ba3c19621464494d",
"reference": "83b179e8097645a30d402d75ba3c19621464494d",
"shasum": ""
},
"require": {
"ext-json": "*",
"illuminate/database": "^11.0|^12.0",
"php": "^8.2",
"phpdocumentor/type-resolver": "^1.5",
"spatie/temporary-directory": "^1.3|^2.0"
},
"require-dev": {
"ext-redis": "*",
"mockery/mockery": "^1.4",
"orchestra/testbench": "^9.0|^10.0",
"pestphp/pest": "^2.0|^3.0",
"pestphp/pest-plugin-laravel": "^2.0|^3.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"spatie/laravel-data": "^2.0.0|^4.0.0",
"spatie/pest-plugin-snapshots": "^2.0",
"spatie/phpunit-snapshot-assertions": "^4.2|^5.0",
"spatie/ray": "^1.36"
},
"suggest": {
"spatie/data-transfer-object": "Allows for DTO casting to settings. (deprecated)"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Spatie\\LaravelSettings\\LaravelSettingsServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Spatie\\LaravelSettings\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ruben Van Assche",
"email": "ruben@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"description": "Store your application settings",
"homepage": "https://github.com/spatie/laravel-settings",
"keywords": [
"laravel-settings",
"spatie"
],
"support": {
"issues": "https://github.com/spatie/laravel-settings/issues",
"source": "https://github.com/spatie/laravel-settings/tree/3.7.0"
},
"funding": [
{
"url": "https://spatie.be/open-source/support-us",
"type": "custom"
},
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2026-02-09T15:22:32+00:00"
},
{
"name": "spatie/shiki-php",
"version": "2.3.3",

View File

@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::create('settings', function (Blueprint $table): void {
$table->id();
$table->string('group');
$table->string('name');
$table->boolean('locked')->default(false);
$table->json('payload');
$table->timestamps();
$table->unique(['group', 'name']);
});
}
};

View File

@ -0,0 +1,11 @@
<?php
use Spatie\LaravelSettings\Migrations\SettingsMigration;
return new class extends SettingsMigration
{
public function up(): void
{
$this->migrator->add('general.current_semester', 1);
}
};