PHP code example of hnhdigital-os / laravel-model-json

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

    

hnhdigital-os / laravel-model-json 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]
];