PHP code example of secretwebmaster / laravel-optionable

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

    

secretwebmaster / laravel-optionable example snippets


use Illuminate\Database\Eloquent\Model;
use Secretwebmaster\LaravelOptionable\Traits\HasOptions;

class Page extends Model
{
    use HasOptions;
}

$rows = $page->getOptions();
$rows = $page->getOptions('theme');
$rows = $page->getOptions('theme', 'header');

$value = $page->getOption('title', 'theme');

$value = $page->getOption('button_text', 'theme', 'hero');

$value = $page->getOption('color', 'theme', 'footer', 'default-color');

$page->getOption('logo', 'theme', null, null, false);

$page->setOption('title', 'Hello World', 'theme');

$page->setOption('image', '/a.jpg', 'theme', 'gallery', 0);
$page->setOption('image', '/b.jpg', 'theme', 'gallery', 1);

$page->setOptions('theme', 'hero', [
    ['key' => 'title', 'value' => 'Welcome'],
    ['key' => 'subtitle', 'value' => 'Enjoy'],
    ['key' => 'button_text', 'value' => 'Click'],
]);

$page->deleteOption('title', 'theme');

$page->deleteOption('image', 'theme', 'gallery', 1);

$page->clearOptions('theme', 'hero');