PHP code example of wovosoft / settings-manager

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

    

wovosoft / settings-manager example snippets


 interface SettingsInterface
 {
     /**
      * @param number | string | array $key When Number (ID) is provided Query is operated by find() method, else by
      *                                      where('key',$key)->first(); for array returns key=>value paired aray
      * @param string|null $group
      * @param bool $getModel If true returns Model instead value
      * @return string | array | null
      */
     public function get($key, string $group = null, bool $getModel = false);

     /**
      * @param string | number $key Should be unique value. NOTE: Do not use number for creating new Settings.
      *                      Only use it when updating. Otherwise, the numeric value will be used as key's value
      * @param mixed $value mixed Arrays will be parsed as JSON
      * @param string|null $group Group Name of the Settings Option
      * @param string $type bootstrap-vue form fields or any kind of fields you want for front-end. This doesn't
      *                      related to backend. In this package we are aiming bootstrap-vue framework for front-end.
      * @param array $options Options usable for Front-End Manipulation. Like Enum DataType
      * @param bool $getModel If true returns Model instead value
      * @param null $model Due the the issue of "key as numeric", $item Model parameter is added. The function
      *                  should get the model by id or check if it is instance of the Settings.php Model. If it is already a
      *                  model do not find it, just perform the operation
      * @return mixed
      */
     public function set($key, $value, string $group = null, $type = "b-form-input", $options = [], bool $getModel = false, $model = null);

     /**
      * @param array $item ['key'=>string | number,'value'=> mixed, 'group'=>string, type'=>string, 'options'=>string | array]
      * @param bool $getModel If true returns Model instead value
      * @return mixed
      */
     public function setArray($item = [], bool $getModel = false);

     /**
      * @param array $key_values [['key'=>string | number, 'value'=>mixed, 'group'=>string, type'=>string, 'options'=>string | array]]
      * @param bool $getModel If true returns Model instead value
      * @return bool
      */
     public function setBatch($key_values = [], bool $getModel = false);

     /**
      * @param string $key
      * @param string|null $group
      * @param bool $getModel If true returns Model instead value
      * @return bool
      */
     public function has($key, string $group = null, bool $getModel = false);

     /**
      * @param string | number $key number from ID and $key for key
      * @param string|null $group
      * @param bool $getModel If true returns Model instead value
      * @return bool Found && Deleted Condition applicable.
      */
     public function delete($key, string $group = null, bool $getModel = false);

     /**
      * @param string|null $group
      * @param bool $getModel If true returns Model instead value
      * @return mixed
      */
     public function all(string $group = null, bool $getModel = false);

     /**
      * @param bool $getModel
      * @return mixed
      */
     public function allGrouped(bool $getModel = false);
 }


use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Wovosoft\SettingsManager\Facades\Settings;

class SettingsController extends Controller
{
    public function set(Request $request)
    {
        try {
            $status = Settings::set(
                $request->post("key"),
                $request->post("value"),
                $request->post("group"),
                $request->post("type"),
                $request->post("options"),
                $request->post("getModel") ?? false,
                $request->post("id") ?? null
            );
            return response()->json([
                "status" => $status,
                "msg" => $status ? "Successfully Done" : "Failed to perform the operation",
                "type" => $status ? "success" : "warning",
                "title" => $status ? "Success" : "Failed"
            ]);
        } catch (\Exception $exception) {
            return response()->json([
                "status" => false,
                "msg" => $exception->getMessage(),
                "title" => "Failed",
                "type" => "danger",
                "file" => $exception->getFile(),
                "line" => $exception->getLine()
            ], $exception->getCode());
        }
    }
}
bash
php artisan vendor:publish --provider="Wovosoft\SettingsManager\ServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Wovosoft\SettingsManager\ServiceProvider" --tag="resources"
bash
php artisan vendor:publish --provider="Wovosoft\SettingsManager\ServiceProvider" --tag="migrations"
bash
php artisan vendor:publish --provider="Wovosoft\SettingsManager\ServiceProvider" --tag="seeds"