style updates

This commit is contained in:
Mark Gregory
2026-07-24 14:59:44 +01:00
parent 24ab771cd3
commit dd23205d0b
482 changed files with 7173 additions and 1435 deletions
@@ -4,13 +4,24 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void {
return new class extends Migration
{
public function up(): void
{
Schema::create('settings', function (Blueprint $table): void {
$table->id(); $table->string('group')->default('general')->index(); $table->string('key');
$table->longText('value')->nullable(); $table->string('type')->default('string'); $table->boolean('is_public')->default(false);
$table->timestamps(); $table->unique(['group','key']);
$table->id();
$table->string('group')->default('general')->index();
$table->string('key');
$table->longText('value')->nullable();
$table->string('type')->default('string');
$table->boolean('is_public')->default(false);
$table->timestamps();
$table->unique(['group', 'key']);
});
}
public function down(): void { Schema::dropIfExists('settings'); }
public function down(): void
{
Schema::dropIfExists('settings');
}
};
@@ -1,7 +1,27 @@
<?php
namespace Modules\Settings\Http\Controllers;
use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Modules\Settings\Models\Setting;
final class SettingController extends Controller {
public function index(){ $settings=Setting::query()->orderBy('group')->orderBy('key')->get(); return view('settings::index',compact('settings')); }
public function update(Request $request){ $data=$request->validate(['settings'=>['array'],'settings.*'=>['nullable','string','max:5000']]); foreach($data['settings']??[] as $id=>$value){ Setting::whereKey($id)->update(['value'=>$value]); } return back()->with('status','Settings saved.'); }
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Settings\Models\Setting;
final class SettingController extends Controller
{
public function index()
{
$settings = Setting::query()->orderBy('group')->orderBy('key')->get();
return view('settings::index', compact('settings'));
}
public function update(Request $request)
{
$data = $request->validate(['settings' => ['array'], 'settings.*' => ['nullable', 'string', 'max:5000']]);
foreach ($data['settings'] ?? [] as $id => $value) {
Setting::whereKey($id)->update(['value' => $value]);
}
return back()->with('status', 'Settings saved.');
}
}
+6 -2
View File
@@ -6,6 +6,10 @@ use Illuminate\Database\Eloquent\Model;
final class Setting extends Model
{
protected $fillable = ['group','key','value','type','is_public'];
protected function casts(): array { return ['is_public'=>'boolean']; }
protected $fillable = ['group', 'key', 'value', 'type', 'is_public'];
protected function casts(): array
{
return ['is_public' => 'boolean'];
}
}
+8 -2
View File
@@ -1,3 +1,9 @@
<?php
use Illuminate\Support\Facades\Route; use Modules\Settings\Http\Controllers\SettingController;
Route::middleware(['auth','verified'])->prefix('administration/settings')->name('administration.settings.')->group(function (): void { Route::get('/',[SettingController::class,'index'])->name('index'); Route::put('/',[SettingController::class,'update'])->name('update'); });
use Illuminate\Support\Facades\Route;
use Modules\Settings\Http\Controllers\SettingController;
Route::middleware(['auth', 'verified'])->prefix('administration/settings')->name('administration.settings.')->group(function (): void {
Route::get('/', [SettingController::class, 'index'])->name('index');
Route::put('/', [SettingController::class, 'update'])->name('update');
});
@@ -8,10 +8,15 @@ use Modules\Settings\Models\Setting;
final class SettingsRepository
{
public function get(string $key, mixed $default = null, string $group = 'general'): mixed
{ return Cache::rememberForever("settings.$group.$key", fn () => Setting::query()->where(compact('group','key'))->value('value') ?? $default); }
{
return Cache::rememberForever("settings.$group.$key", fn () => Setting::query()->where(compact('group', 'key'))->value('value') ?? $default);
}
public function put(string $key, mixed $value, string $group = 'general', string $type = 'string', bool $public = false): Setting
{
$setting = Setting::query()->updateOrCreate(compact('group','key'), ['value'=>is_scalar($value)||$value===null?(string)$value:json_encode($value, JSON_THROW_ON_ERROR),'type'=>$type,'is_public'=>$public]);
Cache::forget("settings.$group.$key"); return $setting;
$setting = Setting::query()->updateOrCreate(compact('group', 'key'), ['value' => is_scalar($value) || $value === null ? (string) $value : json_encode($value, JSON_THROW_ON_ERROR), 'type' => $type, 'is_public' => $public]);
Cache::forget("settings.$group.$key");
return $setting;
}
}
+9 -2
View File
@@ -4,6 +4,13 @@ namespace Modules\Settings\Support;
final class ModuleInfo
{
public static function name(): string { return 'Settings'; }
public static function nameLower(): string { return 'settings'; }
public static function name(): string
{
return 'Settings';
}
public static function nameLower(): string
{
return 'settings';
}
}