feat: add system configuration (A-03) — map center, zoom, radius min/max

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
GuavaPopper
2026-06-05 04:25:58 +07:00
parent 6fa793aec3
commit 2bd7b206a6
11 changed files with 275 additions and 16 deletions
@@ -0,0 +1,28 @@
<?php
namespace App\Http\Controllers;
use App\Models\ActivityLog;
use App\Models\Setting;
use Illuminate\Http\Request;
class SettingController extends Controller
{
public function index()
{
return response()->json(Setting::orderBy('id')->get(['key', 'value', 'label']));
}
public function update(Request $request, string $key)
{
$setting = Setting::where('key', $key)->firstOrFail();
$request->validate(['value' => 'required|string|max:255']);
Setting::set($key, $request->value);
ActivityLog::record('update', "Mengubah konfigurasi: {$setting->label}{$request->value}", 'setting', $key);
return response()->json(['success' => true]);
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
class Setting extends Model
{
protected $fillable = ['key', 'value', 'label'];
public static function getAll(): array
{
return Cache::remember('app_settings', 300, function () {
return static::pluck('value', 'key')->toArray();
});
}
public static function get(string $key, mixed $default = null): mixed
{
return static::getAll()[$key] ?? $default;
}
public static function set(string $key, string $value): void
{
static::where('key', $key)->update(['value' => $value]);
Cache::forget('app_settings');
}
}
+10 -11
View File
@@ -2,23 +2,22 @@
namespace App\Providers;
use App\Models\Setting;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
public function register(): void {}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
View::composer('*', function ($view) {
try {
$view->with('appSettings', Setting::getAll());
} catch (\Throwable) {
$view->with('appSettings', []);
}
});
}
}