PHP code example of agroezinger / filament-app-settings

1. Go to this page and download the library: Download agroezinger/filament-app-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/ */

    

agroezinger / filament-app-settings example snippets


// Write a setting
app_setting()->set('site.name', 'My App');

// Read it back
$name = app_setting('site.name', 'Default');

use Agroezinger\FilamentAppSettings\AppSettings;

$settings = app(AppSettings::class);

// Write
$settings->set('invoice.footer', 'All prices e

// Delete by setting to null or ''
$settings->set('invoice.footer', null);

// Returns the value directly
$value = app_setting('invoice.footer', 'default');

// Returns the AppSettings instance when called without arguments
app_setting()->set('foo', 'bar');
app_setting()->setMany([...]);

$department = Department::find(1);

$settings->set('color', '#ff0000', model: $department);
$settings->get('color', null, model: $department);

$settings->setMany([
    ['key' => 'site.name',    'value' => 'My Club'],
    ['key' => 'site.tagline', 'value' => 'Together we win'],
    // Attach to a model:
    ['key' => 'color', 'value' => '#336699', 'model' => $department],
    // Delete by passing null or '':
    ['key' => 'old.key', 'value' => null],
]);

$settings->set('welcome.text', 'Hello!', explicitTenantId: $team->id);

$settings->setMany([
    ['key' => 'foo', 'value' => 'bar'],
], explicitTenantId: $team->id);

// Returns Collection keyed by model_id
$configs = $settings->getScopedConfigs('color', Department::class);
// ['1' => '#ff0000', '2' => '#336699']

class MyAppSettings extends \Agroezinger\FilamentAppSettings\AppSettings
{
    protected function getTenantId(): int
    {
        return auth()->user()?->team_id ?? 0;
    }
}

// Rebind in a ServiceProvider:
$this->app->singleton(\Agroezinger\FilamentAppSettings\AppSettings::class, fn() => new MyAppSettings());
bash
php artisan vendor:publish --tag="app-settings-migrations"
php artisan migrate