板条 / laravel-metable
一个用于将任意数据附加到 Eloquent 模型的软件包
6.0.4
2024-05-16 02:18 UTC
Requires
- php: >=8.1
- ext-json: *
- illuminate/database: ^10.10|^11.0
- illuminate/support: ^10.10|^11.0
- phpoption/phpoption: ^1.8
Requires (Dev)
- guzzlehttp/guzzle: ^7.2
- guzzlehttp/promises: ^1.4
- laravel/legacy-factories: ^1.0.4
- mockery/mockery: ^1.4.2
- nesbot/carbon: ^2.62.1
- orchestra/testbench: ^8.0|^9.0
- php-coveralls/php-coveralls: ^2.7.0
- phpunit/phpunit: ^10.5
- symfony/symfony: ^6.1|^7.0
This package is auto-updated.
Last update: 2024-09-22 01:41:47 UTC
README
Laravel-Metable 是一个用于轻松将任意数据附加到 Eloquent 模型的软件包。
功能
- 一对一多态关系允许在不调整数据库模式的情况下将数据附加到 Eloquent 模型。
- 类型转换系统允许存储和检索多种不同标量和对象类型的数据。请参阅文档以获取支持的类型列表。
示例用法
将一些元数据附加到一个 eloquent 模型
$post = Post::create($this->request->input()); $post->setMeta('color', 'blue');
通过其元数据查询模型
$post = Post::whereMeta('color', 'blue');
从模型检索元数据
$value = $post->getMeta('color');
安装
- 使用 composer 将软件包添加到您的 Laravel 应用程序中
composer require plank/laravel-metable
- 在
config/app.php
中注册软件包的服务提供者。在 Laravel 5.5 及更高版本中,如果启用了软件包自动发现,则可以跳过此步骤。
'providers' => [ ... Plank\Metable\MetableServiceProvider::class, ... ];
- 使用 artisan 发布软件包的配置文件(
config/metable.php
)。
php artisan vendor:publish --provider="Plank\Metable\MetableServiceProvider"
- 运行迁移以将所需的表添加到您的数据库中。
php artisan migrate
- 将
Plank\Metable\Metable
特性添加到任何您想要附加元数据的 eloquent 模型类中。
注意:如果您需要一个更通用的方式来引用不同的 Metable 模型类,您可以可选地将 Plank\Metable\MetableInterface
应用到您的模型中。
<?php namespace App; use Illuminate\Database\Eloquent\Model; use Plank\Metable\Metable; class Post extends Model { use Metable; //... }
文档
完整的文档可在 ReadTheDocs 上找到。
许可
本软件包在 MIT 许可证(MIT)下发布。
关于 Plank
Plank 是一家位于加拿大蒙特利尔的 Web 开发公司。