PHP code example of bambamboole / filament-settings
1. Go to this page and download the library: Download bambamboole/filament-settings library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bambamboole / filament-settings example snippets
use Bamamboole\FilamentSettings\FilamentSettingsPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
FilamentSettingsPlugin::make()
->groups([
GeneralSettings::class,
MailSettings::class,
]),
]);
}
use Bamamboole\FilamentSettings\SettingGroup;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Support\Icons\Heroicon;
class GeneralSettings extends SettingGroup
{
public static function key(): string
{
return 'general';
}
public function label(): string
{
return 'General';
}
public function icon(): Heroicon
{
return Heroicon::OutlinedCog6Tooth;
}
public function sort(): int
{
return 0;
}
public function casts(): array
{
return [
'launched' => 'boolean',
];
}
public function schema(): array
{
return [
TextInput::make('site_name')->label('Site Name')->maxLength(255),
Toggle::make('launched')->label('Launched'),
];
}
}
public static function canAccess(): bool
{
return auth()->user()->isAdmin();
}
// Get a value (returns null when not set)
$name = settings('general.site-name');
// Get with a default
$name = settings('general.site-name', 'My App');
// Access the repository directly
settings()->set('general.site-name', 'New Name');
use Bamamboole\FilamentSettings\SettingsRepository;
class SomeService
{
public function __construct(private SettingsRepository $settings) {}
public function isLaunched(): bool
{
return $this->settings->bool('general.launched');
}
}