PHPackages                             qlick/laravel-metable - 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. qlick/laravel-metable

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

qlick/laravel-metable
=====================

A package for attaching arbitrary data to Eloquent models

v1.0.1(3y ago)05MITPHPPHP ^8.1

Since Feb 16Pushed 3y agoCompare

[ Source](https://github.com/nelkasovic/laravel-metable)[ Packagist](https://packagist.org/packages/qlick/laravel-metable)[ RSS](/packages/qlick-laravel-metable/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (9)Versions (2)Used By (0)

Laravel-Metable
===============

[](#laravel-metable)

[![Coveralls](https://camo.githubusercontent.com/2fdcb3f495609ae650226f21e2a430f00978a53ae3b041de5349269247d02e63/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f706c616e6b2f6c61726176656c2d6d657461626c652e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/plank/laravel-metable)[![StyleCI](https://camo.githubusercontent.com/faa8d2f6894071c6e9e1aeeaf9894f8c02e7b09e5d5fb56e322c0bab75ad6054/68747470733a2f2f7374796c6563692e696f2f7265706f732f37393134383833322f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/79148832)[![Packagist](https://camo.githubusercontent.com/ddeba39f3cd7ae67807f6888eeecd473caa78a7233b0b78df2d55874fcffc098/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706c616e6b2f6c61726176656c2d6d657461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/plank/laravel-metable)

Laravel-Metable is a package for easily attaching arbitrary data to Eloquent models.

Features
--------

[](#features)

- One-to-many polymorphic relationship allows attaching data to Eloquent models without needing to adjust the database schema.
- Type conversion system allows data of numerous different scalar and object types to be stored and retrieved. See the documentation for the list of supported types.

Example Usage
-------------

[](#example-usage)

Attach some metadata to an eloquent model

```
$post = Post::create($this->request->input());
$post->setMeta('color', 'blue');
```

Query the model by its metadata

```
$post = Post::whereMeta('color', 'blue');
```

Retrieve the metadata from a model

```
$value = $post->getMeta('color');
```

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

[](#installation)

1. Add the package to your Laravel app using composer

```
composer require plank/laravel-metable
```

2. Register the package's service provider in `config/app.php`. In Laravel versions 5.5 and beyond, this step can be skipped if package auto-discovery is enabled.

```
'providers' => [
    ...
    Plank\Metable\MetableServiceProvider::class,
    ...
];
```

3. Publish the config file (`config/metable.php`) of the package using artisan.

```
php artisan vendor:publish --provider="Plank\Metable\MetableServiceProvider"
```

4. Run the migrations to add the required table to your database.

```
php artisan migrate
```

5. Add the `Plank\Metable\Metable` trait to any eloquent model class that you want to be able to attach metadata to.

*Note: If need a more generic way to reference different Metable Model classes, you can optionally apply the `Plank\Metable\MetableInterface` to your models.*

```
