/
DATKAI
/
ITCUP
Обзор
Документация
Войти
/
DATKAI
/
ITCUP
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
app/Filament/Pages/GeneralSettings.php
127 строк
6 KB
DATKAI
feat(settings): страницы настроек ITCUP и управления сертификатом
09 июл 2026, 12:19
09 июл 2026, 12:19
0e80fda
Код
Авторство
О чём код?
<?php namespace App\Filament\Pages; use App\Models\AppSetting; use BackedEnum; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Contracts\HasForms; use Filament\Notifications\Notification; use Filament\Pages\Page; use Filament\Schemas\Components\Section; use Filament\Schemas\Schema; use Filament\Support\Icons\Heroicon; class GeneralSettings extends Page implements HasForms { use InteractsWithForms; protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCog6Tooth; protected static ?string $navigationLabel = 'Настройки системы'; protected static string|\UnitEnum|null $navigationGroup = 'Настройки'; protected static ?int $navigationSort = 1; protected static ?string $title = 'Настройки системы'; protected string $view = 'filament.pages.general-settings'; const GROUP = 'general'; public ?array $data = []; public static function canAccess(): bool { return auth()->user()?->hasRole('admin') ?? false; } public function mount(): void { $saved = AppSetting::getGroup(self::GROUP); $this->form->fill([ 'app_name' => $saved['app_name'] ?? config('app.name'), 'locale' => $saved['locale'] ?? config('app.locale'), 'timezone' => $saved['timezone'] ?? config('app.timezone'), 'mail_from_name' => $saved['mail_from_name'] ?? config('mail.from.name'), 'mail_from_address' => $saved['mail_from_address'] ?? config('mail.from.address'), 'mail_host' => $saved['mail_host'] ?? config('mail.mailers.smtp.host'), 'mail_port' => $saved['mail_port'] ?? config('mail.mailers.smtp.port'), 'mail_username' => $saved['mail_username'] ?? config('mail.mailers.smtp.username'), 'mail_encryption' => $saved['mail_encryption'] ?? config('mail.mailers.smtp.scheme'), ]); } public function form(Schema $schema): Schema { return $schema->components([ Section::make('Общие') ->columns(2) ->schema([ TextInput::make('app_name') ->label('Название системы') ->required() ->maxLength(100), Select::make('locale') ->label('Язык интерфейса') ->options(['ru' => 'Русский', 'en' => 'English']) ->required(), Select::make('timezone') ->label('Часовой пояс') ->searchable() ->options(collect(\DateTimeZone::listIdentifiers())->mapWithKeys(fn ($tz) => [$tz => $tz])) ->required(), ]), Section::make('Почта (SMTP)') ->description('Используется для email-уведомлений: истечение лицензий, заявки, сброс пароля') ->columns(2) ->schema([ TextInput::make('mail_host')->label('SMTP-сервер')->placeholder('smtp.yandex.ru'), TextInput::make('mail_port')->label('Порт')->numeric()->placeholder('465'), TextInput::make('mail_username')->label('Логин')->placeholder('noreply@company.ru'), TextInput::make('mail_password') ->label('Пароль') ->password() ->revealable() ->dehydrated(fn ($state) => filled($state)) ->placeholder('оставьте пустым, чтобы не менять'), Select::make('mail_encryption') ->label('Шифрование') ->options(['ssl' => 'SSL', 'tls' => 'TLS', '' => 'Без шифрования']), TextInput::make('mail_from_address')->label('Email отправителя')->email(), TextInput::make('mail_from_name')->label('Имя отправителя'), ]), ]); } public function save(): void { $data = $this->form->getState(); AppSetting::set(self::GROUP, 'app_name', $data['app_name']); AppSetting::set(self::GROUP, 'locale', $data['locale']); AppSetting::set(self::GROUP, 'timezone', $data['timezone']); AppSetting::set(self::GROUP, 'mail_host', $data['mail_host']); AppSetting::set(self::GROUP, 'mail_port', $data['mail_port']); AppSetting::set(self::GROUP, 'mail_username', $data['mail_username']); AppSetting::set(self::GROUP, 'mail_encryption', $data['mail_encryption']); AppSetting::set(self::GROUP, 'mail_from_address', $data['mail_from_address']); AppSetting::set(self::GROUP, 'mail_from_name', $data['mail_from_name']); if (filled($data['mail_password'] ?? null)) { AppSetting::set(self::GROUP, 'mail_password', $data['mail_password'], encrypted: true); } \Illuminate\Support\Facades\Cache::forget('app_settings.general'); Notification::make() ->title('Настройки сохранены') ->body('Часть параметров (язык по умолчанию, SMTP) применится при следующем запросе.') ->success() ->send(); } }