PHP code example of bluora / laravel-model-json-column

1. Go to this page and download the library: Download bluora/laravel-model-json-column 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/ */

    

bluora / laravel-model-json-column example snippets


use Bluora\LaravelModelJson\JsonColumnTrait;

class User extends Model
{
    use JsonColumnTrait;

    protected $json_columns = [
        'settings'
    ];
}

['showProfilePicture' => true, 'options' => ['option1' => 'red']];

echo $user->settings()->showProfilePicture."\n";
echo $user->settings()->options['option1'];

$user->settings()->options['option2'] = 1;
$user->save();

['showProfilePicture' => true, 'options' => ['option1' => 'red', 'option2' => 1]];

print_r($user->getDirty(true));

$model = Model::firstOrNew(['name' => 'example']);
$model->inspectJson();

array(
    'settings' => "{"showProfilePicture":true,"options":{"option1":"red","option2":1}}",
    'settings.options' => array('option2' => 1)
)

protected $json_defaults = [
    'settings' => ['showProfilePicture' => 0]
];

protected $json_options = [
    'settings' => ['no_saving_default_values' => true]
];