PHP code example of roundly-consulting / options-for-laravel

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

    

roundly-consulting / options-for-laravel example snippets


use RoundlyConsulting\Options\BaseOption;

final class ThemeOption extends BaseOption
{
    public function key(): string
    {
        return 'theme';
    }

    public function default(): mixed
    {
        return 'light';
    }

    public function rules(): array|string
    {
        return ['

use RoundlyConsulting\Options\Facades\Options;

Options::get(ThemeOption::class);                 // 'light' — the default until a value is stored
Options::set(ThemeOption::class, 'dark');         // validated against rules(), cached, fires OptionSet

Options::set(ThemeOption::class, 'light', $user); // scoped to one model
Options::for($user)->get(ThemeOption::class);     // 'light'
Options::forget(ThemeOption::class, $user);       // back to the default
bash
composer vendor:publish --tag="options-migrations"
php artisan migrate