Add complete feature suite: Permissions, Audit Trail, API Auth, Error Tracking, Module System, and Site Settings
- Install spatie/laravel-permission v6.24 with 3 roles (admin, editor, viewer) and 5 base permissions - Install owen-it/laravel-auditing v14.0 for tracking model changes - Install laravel/sanctum v4.3 for API token authentication - Install spatie/laravel-ignition v2.11 and spatie/flare-client-php v1.10 for enhanced error tracking - Add Module System with make:module artisan command for scaffolding features - Create Site Settings page in Filament admin for logo, colors, and configuration - Add comprehensive debugging documentation (DEBUGGING.md, AI_CONTEXT.md updates) - Create FEATURES.md with complete feature reference - Update User model with HasRoles and HasApiTokens traits - Configure Redis cache and OPcache for performance - Add RolePermissionSeeder with pre-configured roles and permissions - Update documentation with debugging-first workflow - All features pre-installed and production-ready
This commit is contained in:
125
src/app/Filament/Pages/Settings.php
Normal file
125
src/app/Filament/Pages/Settings.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class Settings extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';
|
||||
|
||||
protected static string $view = 'filament.pages.settings';
|
||||
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?int $navigationSort = 99;
|
||||
|
||||
public ?array $data = [];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$siteName = Setting::get('site_name', config('app.name'));
|
||||
$siteLogo = Setting::get('site_logo');
|
||||
$primaryColor = Setting::get('primary_color', '#3b82f6');
|
||||
$secondaryColor = Setting::get('secondary_color', '#8b5cf6');
|
||||
$accentColor = Setting::get('accent_color', '#10b981');
|
||||
$siteDescription = Setting::get('site_description');
|
||||
$contactEmail = Setting::get('contact_email');
|
||||
$maintenanceMode = Setting::get('maintenance_mode', false);
|
||||
|
||||
$this->form->fill([
|
||||
'site_name' => is_string($siteName) ? $siteName : config('app.name'),
|
||||
'site_logo' => is_string($siteLogo) || is_null($siteLogo) ? $siteLogo : null,
|
||||
'primary_color' => is_string($primaryColor) ? $primaryColor : '#3b82f6',
|
||||
'secondary_color' => is_string($secondaryColor) ? $secondaryColor : '#8b5cf6',
|
||||
'accent_color' => is_string($accentColor) ? $accentColor : '#10b981',
|
||||
'site_description' => is_string($siteDescription) || is_null($siteDescription) ? $siteDescription : '',
|
||||
'contact_email' => is_string($contactEmail) || is_null($contactEmail) ? $contactEmail : '',
|
||||
'maintenance_mode' => is_bool($maintenanceMode) ? $maintenanceMode : false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Section::make('General Settings')
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('site_name')
|
||||
->label('Site Name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
|
||||
Forms\Components\FileUpload::make('site_logo')
|
||||
->label('Site Logo')
|
||||
->image()
|
||||
->directory('logos')
|
||||
->visibility('public'),
|
||||
|
||||
Forms\Components\Textarea::make('site_description')
|
||||
->label('Site Description')
|
||||
->rows(3)
|
||||
->maxLength(500),
|
||||
|
||||
Forms\Components\TextInput::make('contact_email')
|
||||
->label('Contact Email')
|
||||
->email()
|
||||
->maxLength(255),
|
||||
]),
|
||||
|
||||
Forms\Components\Section::make('Color Scheme')
|
||||
->schema([
|
||||
Forms\Components\ColorPicker::make('primary_color')
|
||||
->label('Primary Color'),
|
||||
|
||||
Forms\Components\ColorPicker::make('secondary_color')
|
||||
->label('Secondary Color'),
|
||||
|
||||
Forms\Components\ColorPicker::make('accent_color')
|
||||
->label('Accent Color'),
|
||||
])
|
||||
->columns(3),
|
||||
|
||||
Forms\Components\Section::make('System')
|
||||
->schema([
|
||||
Forms\Components\Toggle::make('maintenance_mode')
|
||||
->label('Maintenance Mode')
|
||||
->helperText('Enable to put the site in maintenance mode'),
|
||||
]),
|
||||
])
|
||||
->statePath('data');
|
||||
}
|
||||
|
||||
protected function getFormActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('save')
|
||||
->label('Save Settings')
|
||||
->submit('save'),
|
||||
];
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
|
||||
Setting::set('site_name', $data['site_name'] ?? '');
|
||||
Setting::set('site_logo', $data['site_logo'] ?? '');
|
||||
Setting::set('primary_color', $data['primary_color'] ?? '#3b82f6');
|
||||
Setting::set('secondary_color', $data['secondary_color'] ?? '#8b5cf6');
|
||||
Setting::set('accent_color', $data['accent_color'] ?? '#10b981');
|
||||
Setting::set('site_description', $data['site_description'] ?? '');
|
||||
Setting::set('contact_email', $data['contact_email'] ?? '');
|
||||
Setting::set('maintenance_mode', $data['maintenance_mode'] ?? false, 'boolean');
|
||||
|
||||
Notification::make()
|
||||
->title('Settings saved successfully')
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user