https://github.com/dottwatson/laravel-model-meta
A clean and smart tool to add metadata support on your models
https://github.com/dottwatson/laravel-model-meta
Last synced: 5 months ago
JSON representation
A clean and smart tool to add metadata support on your models
- Host: GitHub
- URL: https://github.com/dottwatson/laravel-model-meta
- Owner: dottwatson
- Created: 2022-03-21T10:48:05.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-21T13:17:47.000Z (over 4 years ago)
- Last Synced: 2025-05-31T10:32:38.150Z (about 1 year ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Laravel Model Meta
## _Extend your models with unlimited meta attributes_
[](https://travis-ci.org/joemccann/dillinger)
Easly add meta data to your model, without change any logic. This package can gives you the ability to extend your laravel model with a configurable set of meta data. Each meta will be automatically inserted,upadted or deleted, following your model modifications and lifecycle.
Meta data will be treated exactly like attributes, so they can be cast, hidden, and have accessories and mutators available. You don't need to know any new syntax, as it is all manageable with the standard model conventions.
### Installation
```
composer require dottwtson/laravel-model-meta
```
then publish config files
```
php artisan vendor:publish --tag=model-meta-config
```
##### File config/model-meta-types.php
Here you can set all the available meta types. You can add any kind of meta type for all your needs
```php
[
// This is the casting that will be applied on the query. %s will be replaced with the meta name
'database_casting' => 'CAST(%s.value AS UNSIGNED)',
// This is the model casting, according with laravale casting
'model_casting' => 'int'
],
...
]
```
Fill free to define all your own meta types
#### config/model-meta.php
Here you can define all the meta data available on your model.
```php
[
'mymeta' => ['type'=>\Dottwatson\Meta::JSON,...],
],
...
\My\Namespace\ModelName::class => [
'mymeta' => ['type'=>'json',...], // the type is defined in model-meta-type
...
]
]
```
You can also assign a meta list directly on the model (see below).
#### Implements meta on your existing model
```php
['type'=>'json',...], // the type is defined in model-meta-type
];
}
}
```
For default, the meta data are relationed to the model primary key. For customize it on your needs add this in your model
```php