tobymaxham/laravel-properties
最新稳定版本:v1.1
Composer 安装命令:
composer require tobymaxham/laravel-properties
包简介
This package can be used to add some functionality to your Eloquent Models using properties
README 文档
README
This package can be used to add some functionality to your Eloquent Models using properties.
Installation
You can install the package via composer:
composer require tobymaxham/laravel-properties
Usage
Your Eloquent Models should use the TobyMaxham\LaravelProperties\Traits\UseProperties trait.
The trait contains a few methods to help you handle JSON-Date in your Database Table Column.
Your models' migrations should have a field called properties to save the JSON-Data.
Here's an example of how to implement the trait:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use TobyMaxham\LaravelProperties\Traits\UseProperties; class YourEloquentModel extends Model { use UseProperties; }
With its migration:
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { public function up(): void { Schema::create('your_eloquent_models', function (Blueprint $table) { $table->id(); $table->json('properties'); // ... $table->timestamps(); }); } public function down(): void { Schema::dropIfExists('your_eloquent_models'); } };
Use to store values in your Model
$model = new EloquentModel(); $model->setProperty('key', 'value'); $model->save();
You can also use Laravel's "dot" notation to set a value:
$model->setProperty('foo.bar', 'value');
Receive a value from your Model
$model->getProperty('foo.bar'); // 'value'
You can also pass a default value:
$model->getProperty('foo.baz', 'another Value'); // 'another Value'
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
If you've found a bug regarding security please mail git@maxham.de instead of using the issue tracker.
Support me
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-18