PHP code example of webafra / larasettings

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

    

webafra / larasettings example snippets


'providers' => [
    Webafra\LaraSetting\LaraSettingServiceProvider::class,
],

'aliases' => [
    'Setting' => Webafra\LaraSetting\Facade\Setting::class,
],

use Webafra\LaraSetting\Facade\Setting;

// Store a value
Setting::set('site_name', 'My Website');

// Retrieve a value (with optional default)
$name = Setting::get('site_name', 'Default Name');

// Check if a setting exists
if (Setting::has('site_name')) {
    // ...
}

// Delete a setting
Setting::delete('site_name');

// Store in a specific group
Setting::set('color', '#ffffff', false, 'theme');
Setting::set('font', 'Inter', false, 'theme');

// Retrieve from a group
$color = Setting::get('color', '#000000', 'theme');

// Get all settings in a group as key-value array
$theme = Setting::getGroup('theme');
// ['color' => '#ffffff', 'font' => 'Inter']

// Mark as primary when storing
Setting::set('app_name', 'My App', true);

// Store multiple primaries (arrays are auto JSON-encoded)
Setting::storePrimary([
    'app_name' => 'My App',
    'social_links' => ['twitter' => 'https://...'],
]);

// Retrieve all primary settings as key-value array
$primaries = Setting::getPrimary();

// Store multiple settings at once (optionally in a group)
Setting::store([
    'key1' => 'value1',
    'key2' => 'value2',
], 'my_group');

Setting::clean();

Setting::set(string $key, mixed $value, bool $is_primary = false, string $group = 'general'): mixed

Setting::get(string $key, mixed $default = null, string $group = 'general'): mixed

Setting::has(string $key, string $group = 'general'): bool

Setting::delete(string $key, string $group = 'general'): bool

Setting::store(array $settings, string $group = 'general'): int

Setting::store([
    'key1' => 'value1',
    'key2' => ['a', 'b'],  // arrays are auto JSON-encoded
], 'my_group');

Setting::storePrimary(array $settings, string $group = 'general'): int

Setting::getPrimary(mixed $default = null): mixed

Setting::getGroup(string $group): array

Setting::clean(): void
bash
# Publish only migrations
php artisan vendor:publish --tag=migrations

# Publish only models
php artisan vendor:publish --tag=models

# Publish both
php artisan vendor:publish --tag=all
bash
php artisan migrate
bash
php artisan vendor:publish --tag=migrations
php artisan migrate