vkovic/laravel-meta
Composer 安装命令:
composer require vkovic/laravel-meta
包简介
Laravel meta storage for different purposes
README 文档
README
Laravel database meta storage for different purposes
This is simple package for easy storage and retrieval of all kind (different data types) of metadata for your application in dedicated table.
Compatibility
The package is compatible with Laravel versions 5.5, 5.6, 5.7, 5.8 and 6
Installation
Install the package via composer:
composer require vkovic/laravel-meta
Run migrations to create table which will be used to store our metadata:
php artisan migrate
Usage
Let's create and retrieve some metadata:
// Set meta value as string Meta::set('foo', 'bar'); // Get meta value Meta::get('foo')) // : 'bar' // In case there is no metadata found for given key, // we can pass default value to return Meta::get('baz', 'default'); // : 'default'
Multiple records could be retrieved using query method and wildcard *:
Meta::set('settings.display.resolution', '1280x1024'); Meta::set('settings.display.brightness', 97); Meta::set('settings.sound.volume', 54); Meta::set('settings.mic.volume', 0); Meta::query('settings.display.*'); // Result: // [ // 'settings.display.resolution' => '1280x1024', // 'settings.display.brightness' => 97 // ] Meta::query('*.sound.*'); // Result: // [ // 'settings.sound.volume' => 54 // ] Meta::query('settings.*.volume'); // Result: // [ // 'settings.sound.volume' => 54, // 'settings.mic.volume' => 0 // ] // In case there is no metadata found for given query, // we can pass default value to return Meta::query('settings.sound.bass', 85); // : 85
Beside string, metadata can also be stored as integer, float, null, boolean or array:
Meta::set('age', 35); Meta::set('temperature', 24.7); Meta::set('value', null); Meta::set('employed', true); Meta::set('fruits', ['orange', 'apple']); Meta::get('age'); // : 35 Meta::get('temperature'); // : 24.7 Meta::get('value'); // : null Meta::get('employed'); // : true Meta::get('fruits'); // : ['orange', 'apple']
We can easily check if meta exists without actually retrieving it from meta table:
Meta::set('foo', 'bar'); Meta::exists('foo'); // : true
Counting all meta records is also a breeze:
Meta::set('a', 'one'); Meta::set('b', 'two'); Meta::count(); // : 2
If we need all metadata, or just keys, no problem:
Meta::set('a', 'one'); Meta::set('b', 'two'); Meta::set('c', 'three'); // Get all metadata Meta::all(); // : ['a' => 'one', 'b' => 'two', 'c' => 'three'] // Get only keys Meta::keys(); // : [0 => 'a', 1 => 'b', 2 => 'c']
Also, we can remove meta easily:
Meta::set('a', 'one'); Meta::set('b', 'two'); Meta::set('c', 'three'); // Remove meta by key Meta::remove('a'); // Or array of keys Meta::remove(['b', 'c']);
If, for some reason, we want to delete all meta at once, no problem:
// This will delete all metadata from our meta table! Meta::purge();
If we need to access underlying meta model (Laravel Eloquent Model) to manipulate or retrieve data with unlimited control we can get it like this:
Meta::getModel();
Contributing
If you plan to modify this Laravel package you should run tests that comes with it.
Easiest way to accomplish this would be with Docker, docker-compose and phpunit.
First, we need to initialize Docker containers:
docker-compose up -d
After that, we can run tests and watch the output:
docker-compose exec app vendor/bin/phpunit
Similar packages
The package is one of three metadata packages based on the same approach:
- vkovic/laravel-meta (this package - general purpose meta storage)
- vkovic/laravel-model-meta (Laravel model related meta storage)
- vkovic/laravel-settings (app specific settings meta storage)
Packages can be used separately or together. Internally they are using same table and share common logic.
vkovic/laravel-meta 适用场景与选型建议
vkovic/laravel-meta 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 971 次下载、GitHub Stars 达 6, 最近一次更新时间为 2018 年 12 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「data」 「laravel」 「meta」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vkovic/laravel-meta 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vkovic/laravel-meta 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vkovic/laravel-meta 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Harvest statistics and meta data from an URL or his source code (seo oriented).
Phalcon PHP Meta tags service
Adds the EDTF data type to Wikibase
A simple library that allows transform any kind of data to native php data or whatever
A SilverStripe module to optimise the Meta, crawling, indexing, and sharing of your website content (forked from Cyber-Duck/Silverstripe-SEO)
统计信息
- 总下载量: 971
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 3
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-12-12