定制 dorgan/laravel-living-models 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

dorgan/laravel-living-models

最新稳定版本:v0.0.1

Composer 安装命令:

composer require dorgan/laravel-living-models

包简介

A Laravel enhancement that allows models to define dynamic, calculated, and formula-driven attributes using PHP.

README 文档

README

Living Models (dorgan/laravel-living-models) is a Laravel package that lets you define dynamic, calculated, and formula-driven attributes directly on your Eloquent models, using simple PHP or a small expression language.

Instead of scattering pricing, tax, and business rules across services, you keep them close to the model while still treating them as configuration-like logic.

Quick example

<?php

use Dorgan\LivingModels\LivingModel;

class Product extends LivingModel
{
    protected $table = 'products';

    public function configure(): void
    {
        $this->attribute('name')->string();
        $this->attribute('quantity')->integer();

        // Pure PHP closure
        $this->calculated('unit_price', function () {
            if ($this->quantity >= 100) return 8.50;
            if ($this->quantity >= 50)  return 9.25;
            return 10.00;
        });

        // Uses the small expression language
        $this->formula('extended_price', 'quantity * unit_price');
    }
}

Now you can do:

$product = Product::make(['name' => 'Widget', 'quantity' => 120]);

$product->unit_price;      // 8.50
$product->extended_price;  // 1020.00

Status

Early iteration / alpha – APIs may change as we refine Living Models.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-28