PHP code example of supplycart / settings

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

    

supplycart / settings example snippets




declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Supplycart\Settings\Contracts\HasSettings as HasSettingsContract;
use Supplycart\Settings\Traits\HasSettings;

final class Company extends Model implements HasSettingsContract
{
    use HasSettings;

    public static function getDefaultSettings(): array
    {
        return [
            'timezone' => 'Asia/Kuala_Lumpur',
            'notifications' => [
                'email' => true,
            ],
        ];
    }
}

$company->getSetting();
$company->getSetting('timezone');
$company->getSetting('notifications.email', false);

$company->setSetting('timezone', 'UTC');

$company->setSetting([
    'timezone' => 'UTC',
    'notifications' => ['email' => false],
]);

use App\Models\Setting;

return [
    'model' => Setting::class,
];
bash
composer vendor:publish --tag=settings-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=settings-config