PHPackages                             whilesmart/eloquent-invoices - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. whilesmart/eloquent-invoices

ActiveLibrary[Database &amp; ORM](/categories/database)

whilesmart/eloquent-invoices
============================

Polymorphic invoice management with line items for Laravel applications.

013PHP

Since Apr 25Pushed 1mo agoCompare

[ Source](https://github.com/whilesmartphp/eloquent-invoices)[ Packagist](https://packagist.org/packages/whilesmart/eloquent-invoices)[ RSS](/packages/whilesmart-eloquent-invoices/feed)WikiDiscussions dev Synced 1w ago

READMEChangelogDependenciesVersions (2)Used By (0)

whilesmart/eloquent-invoices
============================

[](#whilesmarteloquent-invoices)

Polymorphic invoice management with line items for Laravel applications. Designed to pair with `whilesmart/eloquent-customers`.

Install
-------

[](#install)

```
composer require whilesmart/eloquent-invoices
php artisan migrate
```

The customers package is a hard dependency — composer will pull it in automatically.

Use
---

[](#use)

Add `HasInvoices` to any model that should own invoices (Workspace, Organization, User, etc.):

```
use Whilesmart\Invoices\Traits\HasInvoices;

class Workspace extends Model
{
    use HasInvoices;
}
```

The trait gives you a `morphMany` relation:

```
$invoice = $workspace->invoices()->create([
    'customer_id' => $customer->id,
    'number' => 'INV-2026-0001',
    'issue_date' => today(),
    'due_date' => today()->addDays(30),
    'currency' => 'USD',
]);

$invoice->lineItems()->create([
    'description' => 'Roofing labour',
    'quantity' => 8,
    'unit' => 'hour',
    'unit_price_cents' => 7500,
]);

$invoice->recalculate()->save();
```

`recalculate()` reads the line items and computes `subtotal_cents`, then applies `discount_cents` and `tax_cents` to set `total_cents`. `balanceCents()` returns the unpaid remainder (`total - amount_paid`).

Endpoints
---------

[](#endpoints)

VerbPathNotes`GET``/api/invoices`List, filter by `owner_type`+`owner_id`, `status`, `customer_id``POST``/api/invoices`Create (with optional nested `line_items`)`GET``/api/invoices/{id}`Show with customer + line items`PUT``/api/invoices/{id}`Update header fields`DELETE``/api/invoices/{id}`Soft delete`POST``/api/invoices/{id}/send`Mark as sent, set `sent_at``POST``/api/invoices/{id}/mark-paid`Apply payment (`amount_cents`), advance status to `partially_paid` or `paid``POST``/api/invoices/{id}/void`Mark as voidPolymorphic line items
----------------------

[](#polymorphic-line-items)

Line items can either be **freehand** (you supply description / quantity / unit\_price\_cents directly) or **bound to an invoiceable model** via a `morphTo` relation. Any model that implements `Whilesmart\Invoices\Contracts\Invoiceable` (or uses the `IsInvoiceable` trait) can be referenced.

```
use Whilesmart\Invoices\Traits\IsInvoiceable;

class LabourRate extends Model
{
    use IsInvoiceable;
    // expose `name`, `default_unit`, `default_price_cents` and the trait does the rest
}
```

Then create an invoice line item by reference:

```
$invoice->lineItems()->create([
    'invoiceable_type' => LabourRate::class,
    'invoiceable_id'   => $rate->id,
    'quantity'         => 8,
    // description / unit / unit_price_cents are pulled from the rate and snapshotted
]);
```

Or via the API:

```
POST /api/invoices
{
  "owner_type": "App\\Models\\Workspace",
  "owner_id": 12,
  "number": "INV-2026-0001",
  "issue_date": "2026-04-07",
  "line_items": [
    { "invoiceable_type": "App\\Models\\LabourRate", "invoiceable_id": 5, "quantity": 8 },
    { "description": "Site cleanup", "quantity": 1, "unit_price_cents": 12000 }
  ]
}
```

Snapshot semantics: when a line item is created from an invoiceable, description / unit / price are **copied** at create time. Later edits to the source model never mutate historical invoices.

Pair with `whilesmart/eloquent-products` for a generic SKU catalog as the first concrete `Invoiceable`.

Status enum
-----------

[](#status-enum)

`Whilesmart\Invoices\Enums\InvoiceStatus`: `draft`, `sent`, `partially_paid`, `paid`, `overdue`, `void`.

Schema
------

[](#schema)

`invoices` table:

columntypeidbigintowner\_type / owner\_idmorphscustomer\_idforeignId nullable → customersnumberunique stringstatusstring (enum)issue\_date / due\_date / sent\_at / paid\_atdatecurrencychar(3)subtotal\_cents / discount\_cents / tax\_cents / total\_cents / amount\_paid\_centsbigintnotes / termstextmetadatajsontimestamps + soft deletes`invoice_line_items` table:

columntypeidbigintinvoice\_idforeignId → invoicespositionunsigned intdescriptionstringquantitydecimal(12,4)unitnullable stringunit\_price\_cents / amount\_centsbigintmetadatajsontimestamps`amount_cents` is auto-computed from `quantity * unit_price_cents` on save.

Config
------

[](#config)

Publish with `php artisan vendor:publish --tag=invoices-config`. Override `register_routes`, `route_prefix`, `route_middleware`, table names, and `number_prefix` via env or the published config file.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance60

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a1ca6f6e01ecbfe6640ff410c4f0321054fb48d05a5f843c2b89887b90369bcd?d=identicon)[whilesmart](/maintainers/whilesmart)

---

Top Contributors

[![nfebe](https://avatars.githubusercontent.com/u/14317775?v=4)](https://github.com/nfebe "nfebe (4 commits)")

### Embed Badge

![Health badge](/badges/whilesmart-eloquent-invoices/health.svg)

```
[![Health](https://phpackages.com/badges/whilesmart-eloquent-invoices/health.svg)](https://phpackages.com/packages/whilesmart-eloquent-invoices)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8361.6M87](/packages/propel-propel1)[mpociot/laravel-composite-key

Support composite keys in your laravel app.

3544.8k1](/packages/mpociot-laravel-composite-key)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
