PHP code example of qmas / laravel-metadata-trait

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

    

qmas / laravel-metadata-trait example snippets


$model->saveSetting(array $settings);

$model->hasSetting(string $key);   // return true or false

$model->hasSettings(array $keys, bool $any = false);   // return true or false

// When $any is FALSE, method will return TRUE only if model has all given setting keys
// Otherwise, method will return TRUE if model has any of the given setting keys 

$model->getSetting(string $key, $defaultValue);

$model->getSettings(array $keys);

$post = Post::whereSetting('setting_key', $settingValue)->get();

$post = Post::whereSetting('key->sub_key->sub_sub_key', $settingValue)->get();
$post = Post::whereSetting('key.sub_key.sub_sub_key', $settingValue)->get();

$post = Post::whereSetting('key->sub_key->sub_sub_key', ['value_1', 'value_2'])->get();
$post = Post::whereSetting('key.sub_key.sub_sub_key', ['value_1', 'value_2'])->get();
bash
php artisan vendor:publish --provider="r94ever\LaravelModelSetting\ModelSettingServiceProvider"
bash
php artisan migrate