PHP code example of remzikocak / laravel-options

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

    

remzikocak / laravel-options example snippets

 bash
php artisan vendor:publish --provider="RKocak\Options\OptionsServiceProvider"
php artisan migrate
 php 
Options::get('optionName');

// You can pass a second parameter as default value
Options::get('optionName', null);

// or use the helper function
options('optionName', null);
 php
Options::has('optionName');
 php
Options::getLoader()->rebuildCache();
 php


namespace App;

use RKocak\Options\Models\Option;
use RKocak\Options\Type;

class MyType extends Type
{

    /**
     * @return string
     */
    public static function getName(): string
    {
        return 'my_type';
    }

    /**
     * @param Option $option
     * @return string
     */
    public function render(Option $option): string
    {
        return '<div>
                    <input type="text" name="options['. htmlspecialchars($option->name) .']" id="options['. htmlspecialchars($option->name) .']" value="'. htmlspecialchars($option->getValue()) .'" class=""/>
                </div>';
    }

    /**
     * Store the new value
     *
     * @param $newValue
     * @param $oldValue
     * @return mixed
     */
    public function store($newValue, $oldValue)
    {
        return $newValue;
    }

    /**
     * Cast value
     *
     * @param $value
     * @return mixed|string
     */
    public function cast($value)
    {
        return (string) $value;
    }

}