PHPackages                             xx19941215/laravel-print-template - 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. [Framework](/categories/framework)
4. /
5. xx19941215/laravel-print-template

ActiveLibrary[Framework](/categories/framework)

xx19941215/laravel-print-template
=================================

Print template management package for Laravel framework

1.0.4(5mo ago)021MITPHPPHP ^7.4 || ^8.0

Since Nov 7Pushed 5mo agoCompare

[ Source](https://github.com/xx19941215/laravel-print-template)[ Packagist](https://packagist.org/packages/xx19941215/laravel-print-template)[ RSS](/packages/xx19941215-laravel-print-template/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (6)Used By (0)

Laravel Print Template
======================

[](#laravel-print-template)

基于Laravel框架实现的打印模板管理功能，提供完整的增删改查API接口。

功能特性
----

[](#功能特性)

- 打印模板的创建、读取、更新、删除操作
- 模板配置以JSON格式存储
- 自动生成模板编码（DY+四位数字格式）
- 使用oh86/laravel-http-tools包构建标准化JSON响应
- 支持软删除
- 支持关联资源
- 支持组织ID隔离（多租户）
- 自动从认证Guard获取用户ID和组织ID作为创建人和修改人信息
- 支持预加载创建者和修改者用户信息

安装
--

[](#安装)

```
composer require xx19941215/laravel-print-template
```

```
php artisan vendor:publish --provider="Xx19941215\PrintTemplate\PrintTemplateServiceProvider"
```

```
php artisan migrate
```

配置
--

[](#配置)

发布配置文件后，可以在 `config/print_template.php` 中进行配置：

- `user_model`: 用户模型类路径（默认: App\\Models\\Admin）
- `routes`: API路由配置

可以通过环境变量设置用户模型类路径：

```
PRINT_TEMPLATE_USER_MODEL=App\\Models\\Admin
```

数据库结构
-----

[](#数据库结构)

打印模板表包含以下字段：

- `id`: 主键
- `org_id`: 组织ID（用于多租户隔离）
- `assoc_type`: 关联资源类型
- `assoc_id`: 关联资源ID
- `code`: 模板编码（DY+四位数字格式）
- `name`: 模板名称
- `config`: 模板配置(JSON格式)
- `creator_id`: 创建人ID
- `modifier_id`: 修改人ID
- `modified_at`: 修改时间
- `deleted_at`: 软删除时间
- `created_at`: 创建时间
- `updated_at`: 更新时间

API接口
-----

[](#api接口)

### 获取模板列表

[](#获取模板列表)

```
GET /printTemplate/list

```

参数：

- offset: 偏移量（必填）
- limit: 限制数量（必填）
- assoc\_type: 关联资源类型（可选）
- assoc\_id: 关联资源ID（可选）
- name: 模板名称（模糊搜索，可选）
- with\_creator: 是否返回创建者信息（布尔值，默认false，可选）
- with\_modifier: 是否返回修改者信息（布尔值，默认false，可选）

响应示例：

```
{
    "code": 0,
    "message": "ok",
    "data": {
        "total": 1,
        "list": [
            {
                "id": 1,
                "org_id": 1,
                "assoc_type": null,
                "assoc_id": null,
                "code": "DY0001",
                "name": "销售合同模板",
                "config": {
                    "template": "...",
                    "settings": {
                        "orientation": "portrait",
                        "paper_size": "A4"
                    }
                },
                "creator_id": 1,
                "modifier_id": 1,
                "modified_at": "2023-01-01 12:00:00",
                "created_at": "2023-01-01 12:00:00",
                "updated_at": "2023-01-01 12:00:00",
                "deleted_at": null,
                "creator": {
                    "id": 1,
                    "name": "张三",
                    // ... 其他用户字段
                },
                "modifier": {
                    "id": 1,
                    "name": "张三",
                    // ... 其他用户字段
                }
            }
        ]
    }
}
```

### 创建模板

[](#创建模板)

```
POST /printTemplate/create

```

参数：

- assoc\_type: 关联资源类型（必填）
- assoc\_id: 关联资源ID（可选）
- name: 模板名称（必填）
- config: 模板配置（数组格式，可选）

注意：org\_id、creator\_id和modifier\_id字段会自动从认证Guard中获取当前用户信息。

### 获取模板详情

[](#获取模板详情)

```
GET /printTemplate

```

参数：

- id: 模板ID（必填）
- with\_creator: 是否返回创建者信息（布尔值，默认false，可选）
- with\_modifier: 是否返回修改者信息（布尔值，默认false，可选）

### 更新模板

[](#更新模板)

```
POST /printTemplate/update

```

参数：

- id: 模板ID（必填）
- assoc\_type: 关联资源类型（必填）
- assoc\_id: 关联资源ID（可选）
- name: 模板名称（必填）
- config: 模板配置（数组格式，可选）

注意：modifier\_id字段会自动从认证Guard中获取当前用户ID。

### 删除模板

[](#删除模板)

```
POST /printTemplate/delete

```

参数：

- id: 模板ID（必填）

响应格式
----

[](#响应格式)

所有API接口均使用oh86/laravel-http-tools包返回标准化JSON格式响应：

成功响应：

```
{
    "code": 0,
    "message": "ok",
    "data": {}
}
```

错误响应：

```
{
    "code": 1,
    "message": "错误信息",
    "data": null
}
```

使用示例
----

[](#使用示例)

```
use Xx19941215\PrintTemplate\Models\PrintTemplate;

// 创建模板
$template = new PrintTemplate();
$template->assoc_type = 'contract';
$template->name = '销售合同模板';
$template->config = [
    'template' => '销售合同模板内容',
    'settings' => [
        'orientation' => 'portrait',
        'paper_size' => 'A4'
    ]
];
// org_id、creator_id和modifier_id会自动设置
$template->modified_at = now();
$template->save();

// 自动生成编码
$template->code = PrintTemplate::genCode($orgId);
$template->save();

// 获取模板编码
echo $template->code; // 输出: DY0001

// 获取模板列表（包含创建者和修改者信息）
$templates = PrintTemplate::with(['creator', 'modifier'])->get();

// 获取模板列表（通过参数控制是否包含创建者和修改者信息）
$templates = PrintTemplate::when($withCreator, function ($query) {
    return $query->with('creator');
})->when($withModifier, function ($query) {
    return $query->with('modifier');
})->get();
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance70

Regular maintenance activity

Popularity6

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

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.

###  Release Activity

Cadence

Every ~15 days

Total

5

Last Release

178d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10104328?v=4)[xiaoxiao.ust](/maintainers/xx19941215)[@xx19941215](https://github.com/xx19941215)

### Embed Badge

![Health badge](/badges/xx19941215-laravel-print-template/health.svg)

```
[![Health](https://phpackages.com/badges/xx19941215-laravel-print-template/health.svg)](https://phpackages.com/packages/xx19941215-laravel-print-template)
```

###  Alternatives

[laravel/octane

Supercharge your Laravel application's performance.

4.0k26.6M223](/packages/laravel-octane)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[code16/sharp

Laravel Content Management Framework

79164.7k8](/packages/code16-sharp)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)[codewithdennis/larament

Larament is a time-saving starter kit to quickly launch Laravel 13.x projects. It includes FilamentPHP 5.x pre-installed and configured, along with additional tools and features to streamline your development workflow.

3991.8k](/packages/codewithdennis-larament)[r2luna/brain

Brain: A process-driven architecture alternative for your Laravel Application.

6338.7k1](/packages/r2luna-brain)

PHPackages © 2026

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