whilesmart/eloquent-accounts 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

whilesmart/eloquent-accounts

Composer 安装命令:

composer require whilesmart/eloquent-accounts

包简介

Polymorphic financial account records for Laravel: bank accounts, mobile money wallets, card processors, cash registers. Attachable to payments and expenses.

README 文档

README

Polymorphic financial account records for Laravel. Bank accounts, mobile money wallets, card processors, cash registers, crypto wallets. Attaches on the account side of whilesmart/eloquent-payments and whilesmart/eloquent-expenses.

Why

eloquent-payments and eloquent-expenses both carry a nullable account polymorph. Without a concrete account model those fields go unused; reporting can't answer "what's in the Lagos UBA account right now?" or "how much came in through MTN MoMo this month?"

This package fills that gap. It is optional: if you don't install it, the morph columns on payments / expenses stay null and nothing breaks.

Install

composer require whilesmart/eloquent-accounts
php artisan migrate

Attach HasAccounts to the model that owns accounts (typically a workspace):

use Whilesmart\Accounts\Traits\HasAccounts;

class Workspace extends Model
{
    use HasAccounts;
}

Data model

One accounts table. Each row belongs polymorphically to an owner and holds:

  • Identity: name, type (bank | mobile_money | card_processor | wallet | cash | crypto | other), status (active | closed | frozen).
  • Provider: provider (string, e.g. UBA, MTN MoMo, Stripe), provider_reference, identifier (account number / last 4 / wallet number, safe to display).
  • Money: currency, opening_balance_cents, balance_cents.
  • is_primary: default account for its owner + currency. Helper primaryAccount(string $currency = null) on the owner.
  • metadata: JSON.

type and provider are free-form strings at the DB level so new rails don't need migrations; AccountType enum carries the canonical values.

Balance

Two modes:

  1. Computed (default, ACCOUNTS_COMPUTE_BALANCE=true): when you read an account, balance_cents is derived as opening_balance_cents + succeeded inbound payments - succeeded outbound payments - paid expenses. Requires whilesmart/eloquent-payments and/or whilesmart/eloquent-expenses; gracefully degrades if they are not installed.
  2. Stored (ACCOUNTS_COMPUTE_BALANCE=false): reads the balance_cents column. Call $account->refreshBalance() (or POST /api/accounts/{id}/refresh-balance) to recompute and persist.

Routes

GET    /api/accounts
POST   /api/accounts
GET    /api/accounts/{account}
PUT    /api/accounts/{account}
DELETE /api/accounts/{account}
POST   /api/accounts/{account}/refresh-balance

Index filters: owner_type, owner_id, type, status, currency, q, per_page.

Config

php artisan vendor:publish --tag=accounts-config:

return [
    'register_routes' => env('ACCOUNTS_REGISTER_ROUTES', true),
    'route_prefix' => env('ACCOUNTS_ROUTE_PREFIX', 'api'),
    'route_middleware' => ['api', 'auth:sanctum'],
    'table' => env('ACCOUNTS_TABLE', 'accounts'),
    'compute_balance' => env('ACCOUNTS_COMPUTE_BALANCE', true),
];

Siblings

  • whilesmart/eloquent-payments -- inbound / outbound transfers. Each Payment has account_type + account_id.
  • whilesmart/eloquent-expenses -- expenses, paid from accounts.
  • whilesmart/eloquent-invoices -- invoices (money in). Tracks summary totals on the invoice row; actual payment records live in eloquent-payments, which reference an Account.

whilesmart/eloquent-accounts 适用场景与选型建议

whilesmart/eloquent-accounts 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 45 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 whilesmart/eloquent-accounts 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 whilesmart/eloquent-accounts 我们能提供哪些服务?
定制开发 / 二次开发

基于 whilesmart/eloquent-accounts 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-24