承接 vkovic/laravel-meta 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vkovic/laravel-meta

Composer 安装命令:

composer require vkovic/laravel-meta

包简介

Laravel meta storage for different purposes

README 文档

README

Build Downloads Stable License

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:

Packages can be used separately or together. Internally they are using same table and share common logic.

统计信息

  • 总下载量: 971
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 2
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-12-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固