PHP code example of shopapps / laravel-settings

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

    

shopapps / laravel-settings example snippets


// Read a setting (falls back to config(), then null)
$siteName = setting('site.name');

// Read with a default
$perPage = setting('pagination.per_page', 15);

// Write a setting
setting_add('site.name', 'My Application');

// Delete a setting
setting_delete('site.name');

// Returns: DB value → config() fallback → null
$value = setting('mail.from_address');

// With an explicit default (skips config fallback)
$value = setting('mail.from_address', '[email protected]');

// For the currently authenticated user
$value = setting('theme', 'light', true);

// For a specific user
$value = setting('theme', 'light', $userId);

setting_add('notifications', ['email' => true, 'sms' => false], 'array');

// Read a nested value
$emailEnabled = setting('notifications.email'); // true

// Simple string
setting_add('site.name', 'My App');

// Boolean
setting_add('maintenance_mode', true, 'boolean');

// Array / JSON
setting_add('mail.recipients', ['[email protected]', '[email protected]'], 'array');

// User-specific setting
setting_add('theme', 'dark', 'string', $userId);

// Global setting
setting_delete('site.name');

// User-specific setting
setting_delete('theme', $userId);

// Flush all cached settings (pre-cache + per-key caches)
setting_clear_cache();

use Shopapps\LaravelSettings\Services\SettingService;

$service = SettingService::make(); // singleton instance

$value = $service->get('site.name');
$service->add('site.name', 'My App');
$service->delete('site.name');
$service->clearAll();

// app/Providers/Filament/AdminPanelProvider.php

use Shopapps\LaravelSettings\LaravelSettingsPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            LaravelSettingsPlugin::make(),
        ]);
}
bash
php artisan vendor:publish --tag="settings-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="settings-config"
bash
php artisan config:cache
php artisan route:cache
php artisan settings:cache