https://github.com/appstract/laravel-meta
Metadata for Eloquent model
https://github.com/appstract/laravel-meta
laravel laravel-meta laravel-package metadata php
Last synced: 3 months ago
JSON representation
Metadata for Eloquent model
- Host: GitHub
- URL: https://github.com/appstract/laravel-meta
- Owner: appstract
- License: mit
- Created: 2017-05-04T13:56:59.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-19T20:31:08.000Z (over 1 year ago)
- Last Synced: 2025-03-29T09:09:32.880Z (3 months ago)
- Topics: laravel, laravel-meta, laravel-package, metadata, php
- Language: PHP
- Homepage:
- Size: 41 KB
- Stars: 128
- Watchers: 7
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Meta
[](https://packagist.org/packages/appstract/laravel-meta)
[](https://packagist.org/packages/appstract/laravel-meta)
[](LICENSE.md)
[](https://travis-ci.org/appstract/laravel-meta)Metadata for your Eloquent model
## Installation
You can install the package via composer:
```bash
composer require appstract/laravel-meta
```### Publish, migrate
By running `php artisan vendor:publish --provider="Appstract\Meta\MetaServiceProvider"` in your project all files for this package will be published. For this package, it's only a migration. Run `php artisan migrate` to migrate the table. There will now be a table named `metas` in your database.
## Usage
You can easily add Meta to an Eloquent model. Just add this to your model:
```php
use Appstract\Meta\Metable;class Book extends Model
{
use Metable;
}
```Then you can get, add, update and delete meta to the model.
```php
$book = Book::find(1);$book->addMeta('someKey', 'someValue');
$book->getMeta('someKey');
$book->getMetaValue('someKey');
$book->hasMeta('someKey');
$book->updateMeta('someKey', 'anotherValue');
$book->addOrUpdateMeta('someKey', 'someValue');
$book->deleteMeta('someKey');
$book->getAllMeta();
$book->deleteAllMeta();
```## Testing
```bash
$ composer test
```## Contributing
Contributions are welcome, [thanks to y'all](https://github.com/appstract/laravel-meta/graphs/contributors) :)
## About Appstract
Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment and write about related subjects on [Medium](https://medium.com/appstract). You can [follow us on Twitter](https://twitter.com/appstractnl), [buy us a beer](https://www.paypal.me/appstract/10) or [support us on Patreon](https://www.patreon.com/appstract).
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.