PHP code example of little-apps / serializable-model

1. Go to this page and download the library: Download little-apps/serializable-model 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/ */

    

little-apps / serializable-model example snippets


use LittleApps\SerializableModel\Serializable;
use Illuminate\Database\Eloquent\Model;

class Foo extends Model {
   use Serializable;
}

use LittleApps\SerializableModel\Serializable;
use Illuminate\Database\Eloquent\Model;

class Foo extends Model {
   use Serializable;
   
   protected $serializable = [
       'column1',
       'column2',
       'column3',
       'column4',
   ];
}

$foo = new Foo();

// Will be stored in the database as "i:9999;"
$foo->column1 = 9999;

// Will be stored in the database as "a:1:{s:3:"key";s:5:"value";}"
$foo->column2 = ['key' => 'value'];

// Will be stored in the database as "d:96.67;"
$foo->column3 = 96.67;

// Will be stored in the database as "Hello World"
$foo->column4 = 'Hello World';

// $value will be set to 9999
$value = $foo->column1;

// $value will be set to ['key' => 'value']
$value = $foo->column2;

// $value will be set to 96.67
$value = $foo->column3;

// $value will be set to "Hello World"
$value = $foo->column4;

Schema::table('foo', function (Blueprint $table) {
    $table->binary('column1');
});