PHPackages                             little-apps/serializable-model - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. little-apps/serializable-model

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

little-apps/serializable-model
==============================

Simple package for serializable columns in a Laravel model.

v1.0.1(6y ago)1662[28 issues](https://github.com/SameOldNick/SerializableModel/issues)MITPHPCI failing

Since Sep 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/SameOldNick/SerializableModel)[ Packagist](https://packagist.org/packages/little-apps/serializable-model)[ RSS](/packages/little-apps-serializable-model/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

SerializableModel
=================

[](#serializablemodel)

[![Build Status](https://camo.githubusercontent.com/0080c850c734c1f84b0b588277fcaa4e531fe55ff07e3020af96c758110761b3/68747470733a2f2f7472617669732d63692e6f72672f6c6974746c652d617070732f53657269616c697a61626c654d6f64656c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/little-apps/SerializableModel) [![Coverage Status](https://camo.githubusercontent.com/dc776b41ceb439e8ab50e24514a122d2f286df3ccf8a3674f493ff4831e6d45d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6c6974746c652d617070732f53657269616c697a61626c654d6f64656c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/little-apps/SerializableModel?branch=master) [![Latest Stable Version](https://camo.githubusercontent.com/358a81cdc81c1c12f5e6e6805aef2521f2754e83e039dcd58857f152ff53b122/68747470733a2f2f706f7365722e707567782e6f72672f6c6974746c652d617070732f73657269616c697a61626c652d6d6f64656c2f762f737461626c65)](https://packagist.org/packages/little-apps/serializable-model) [![Total Downloads](https://camo.githubusercontent.com/441a926de0cb7e6a06037203e77117fc41764a2cac04917ae368b2f481f9e8b2/68747470733a2f2f706f7365722e707567782e6f72672f6c6974746c652d617070732f73657269616c697a61626c652d6d6f64656c2f646f776e6c6f616473)](https://packagist.org/packages/little-apps/serializable-model) [![Latest Unstable Version](https://camo.githubusercontent.com/a33a0c69b357d7340ec13b6e75f4daa8aab3918a986fb850fc88e84f606ec6de/68747470733a2f2f706f7365722e707567782e6f72672f6c6974746c652d617070732f73657269616c697a61626c652d6d6f64656c2f762f756e737461626c65)](https://packagist.org/packages/little-apps/serializable-model) [![License](https://camo.githubusercontent.com/c3851d91d5d0b4f7634eaf5d62597b7401369458f7e8c0df6cd2c40508309475/68747470733a2f2f706f7365722e707567782e6f72672f6c6974746c652d617070732f73657269616c697a61626c652d6d6f64656c2f6c6963656e7365)](https://packagist.org/packages/little-apps/serializable-model)

SerializableModel is simple package for serializable columns in a Laravel model. It utilizes the [`serialize`](http://php.net/manual/en/function.serialize.php) and [`unserialize`](http://php.net/manual/en/function.unserialize.php) PHP functions to store values in the database.

License
-------

[](#license)

SerializableModel is free and open source, and is licensed under the MIT License.

```
Copyright 2018 Little Apps

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

```

Installation
------------

[](#installation)

Install using composer:

```
cd /path/to/laravel/app
composer require little-apps/serializable-model
```

Usage
-----

[](#usage)

This package includes a [trait](http://php.net/trait) which can be included in any class that inherits `Illuminate\Database\Eloquent\Model`.

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

class Foo extends Model {
   use Serializable;
}
```

The next step is to define the columns that should be serialized in the `$serializable` property.

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

class Foo extends Model {
   use Serializable;

   protected $serializable = [
       'column1',
       'column2',
       'column3',
       'column4',
   ];
}
```

Any value that is assigned to the `addresses` or `phone_numbers` columns will stored in the database as a string representation of the original data type.

```
$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';
```

The value of columns are unserialized (if nesessary) and returned. The following follows the values set in the example above.

```
// $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;
```

Database Migrations
-------------------

[](#database-migrations)

The data type to use for a serializable column in a MySQL database can vary. The PHP documentation for [`serializable`](http://php.net/manual/en/function.serialize.php) and [this answer on StackOverflow](https://stackoverflow.com/a/10771079/533242) recommends it be a `BLOB`, and not `CHAR` or `TEXT`. The command for a `BLOB` in a Laravel database migration is `binary()`.

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

Notes
-----

[](#notes)

- To save space in the database, strings are left as is and not serialized.
- [Resources](http://php.net/manual/en/language.types.resource.php) can't be serialized and trying to do so will result in undefined behavior.

Show Your Support
-----------------

[](#show-your-support)

Little Apps relies on people like you to keep our software running. If you would like to show your support for Little System Cleaner, then you can [make a donation](https://www.little-apps.com/?donate) using PayPal, Payza or credit card (via Stripe). Please note that any amount helps (even just $1).

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance8

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~219 days

Total

2

Last Release

2262d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1192535?v=4)[Little Apps, Ltd.](/maintainers/little-apps)[@little-apps](https://github.com/little-apps)

---

Top Contributors

[![SameOldNick](https://avatars.githubusercontent.com/u/110937288?v=4)](https://github.com/SameOldNick "SameOldNick (31 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/little-apps-serializable-model/health.svg)

```
[![Health](https://phpackages.com/badges/little-apps-serializable-model/health.svg)](https://phpackages.com/packages/little-apps-serializable-model)
```

###  Alternatives

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M88](/packages/mongodb-laravel-mongodb)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)[staudenmeir/laravel-adjacency-list

Recursive Laravel Eloquent relationships with CTEs

1.6k5.2M33](/packages/staudenmeir-laravel-adjacency-list)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.2M19](/packages/bavix-laravel-wallet)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.4M2](/packages/glushkovds-phpclickhouse-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
