innonazarene/prism-init 问题修复 & 功能扩展

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

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

innonazarene/prism-init

Composer 安装命令:

composer require innonazarene/prism-init

包简介

Laravel Artisan command to scaffold models, services, controllers, requests, resources, policies and API routes from your database.

README 文档

README

CI Latest Version PHP Laravel License

Prism Init scaffolds a complete, convention-following backend API from your existing database in one command.

What gets generated per table

Artifact Path (grouped, default)
Eloquent Model app/Models/Employee/Employee.php
Service app/Services/Employee/EmployeeService.php
Controller app/Http/Controllers/Api/V1/Employee/EmployeeController.php
Store Request app/Http/Requests/Employee/StoreEmployeeRequest.php
Update Request app/Http/Requests/Employee/UpdateEmployeeRequest.php
API Resource app/Http/Resources/Employee/EmployeeResource.php
Policy app/Policies/Employee/EmployeePolicy.php
API Routes routes/api.phpRoute::apiResource('employees', …)

Plus, once:

Artifact Path
ApiResponse Trait app/Traits/ApiResponse.php

Conventions followed

Database (3.3.1)

  • Table names: snake_case, plural (employees, salary_grades)
  • Model names: PascalCase, singular (Employee)
  • Soft deletes: deleted_at on every model (configurable)
  • Timestamps: created_at, updated_at on every model

PHP / Laravel (3.3.2)

  • Models: PascalCase singular, $fillable, $casts, SoftDeletes — columns auto-populated from DB
  • Controllers: thin — validate → delegate to Service → return Resource
  • Services: all business logic inside DB::transaction() where needed, list() returns paginated results
  • Requests: Store{Model}Request / Update{Model}Request — validation rules inferred from DB column types
  • Resources: {Model}Resource — all fields auto-populated from DB columns
  • Policies: {Model}Policy with all standard gates stubbed
  • Response envelope: consistent { success, data, message, errors } via ApiResponse trait

Requirements

PHP ^8.1
Laravel ^10 | ^11 | ^12 | ^13

Installation

composer require innonazarene/prism-init --dev

Publish the config if you want to customise defaults:

php artisan vendor:publish --tag=prism-init-config

Publish stubs to customise them (optional):

php artisan vendor:publish --tag=prism-init-stubs
# → published to stubs/prism-init/

Usage

php artisan prism:init

Options

Option Description
--prefix=v1 Route prefix (default: v1/api/v1/…)
--grouped Force grouped folder structure
--flat Force flat folder structure
--no-timestamps Disable $timestamps on models
--no-soft-deletes Skip SoftDeletes on models
--skip-migrate Skip migration generation
--skip-seed Skip seeding
--skip-services Skip Service class generation
--skip-resources Skip API Resource generation
--skip-policies Skip Policy generation
--tables=users,products Only scaffold listed tables
--force Overwrite existing files

Examples

# Full scaffold, version prefix v2
php artisan prism:init --prefix=v2

# Only two tables, flat structure
php artisan prism:init --tables=orders,products --flat

# Skip migrations and seeds (DB already set up)
php artisan prism:init --skip-migrate --skip-seed

# No soft deletes, no policies
php artisan prism:init --no-soft-deletes --skip-policies

Generated output example

Given a departments table, Prism Init produces:

app/Models/Department/Department.php

class Department extends Model
{
    use SoftDeletes;

    protected $table = 'departments';

    protected $fillable = [
        'name',
        'code',
        'description',
    ];

    protected $casts = [
        'deleted_at' => 'datetime',
    ];
}

app/Services/Department/DepartmentService.php

public function list(array $filters = []): LengthAwarePaginator
{
    $perPage = isset($filters['per_page']) ? (int) $filters['per_page'] : 15;

    return Department::query()
        ->latest()
        ->paginate($perPage);
}

app/Http/Controllers/Api/V1/Department/DepartmentController.php

class DepartmentController extends Controller
{
    use ApiResponse;

    public function __construct(
        private readonly DepartmentService $service
    ) {}

    public function index(Request $request): JsonResponse
    {
        $data = $this->service->list($request->all());
        return $this->successResponse(DepartmentResource::collection($data), 'Department list retrieved.');
    }

    // store / show / update / destroy …
}

app/Http/Requests/Department/StoreDepartmentRequest.php

public function rules(): array
{
    return [
        'name'        => 'required|string|max:255',
        'code'        => 'required|string|max:50',
        'description' => 'sometimes|nullable|string',
    ];
}

app/Http/Resources/Department/DepartmentResource.php

public function toArray(Request $request): array
{
    return [
        'id'          => $this->id,
        'name'        => $this->name,
        'code'        => $this->code,
        'description' => $this->description,
        'created_at'  => $this->created_at,
        'updated_at'  => $this->updated_at,
    ];
}

app/Traits/ApiResponse.php — envelope methods:

// Success:   { success: true,  data: T,    message: string, errors: null }
// Error:     { success: false, data: null, message: string, errors: object }
// Paginated: { success: true,  data: T[],  meta: { current_page, last_page, per_page, total }, … }

routes/api.php

use App\Http\Controllers\Api\V1\Department\DepartmentController;

Route::prefix('v1')->group(function () {
    Route::apiResource('departments', DepartmentController::class);
});

Customising stubs

After publishing stubs (--tag=prism-init-stubs), edit any file in stubs/prism-init/. Prism Init always prefers your published stub over the package default.

Available stubs:

Stub Purpose
model.stub Eloquent model
service.stub Service class
controller.stub API controller
Store-request.stub Store Form Request
Update-request.stub Update Form Request
resource.stub API Resource
policy.stub Policy
api-response.stub ApiResponse trait

Optional Packages

Prism Init detects these packages at runtime. If installed, they are used automatically — if not, the step is skipped with an install hint.

Package Purpose
kitloong/laravel-migrations-generator Generate migrations from existing DB
orangehill/iseed Generate seeders from live data

Backup & re-running

On every run, Prism saves clean copies of routes/api.php and Controller.php to public/backup/ and restores them before regenerating — so you always start from a clean slate.

Contributing

Pull requests welcome. Please open an issue first to discuss changes.

git checkout -b feat/my-feature
# … make changes …
vendor/bin/phpunit
git push && open PR

License

MIT — see LICENSE.

innonazarene/prism-init 适用场景与选型建议

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

它主要适用于以下技术方向: 「php」 「rest」 「api」 「backend」 「laravel」 「scaffolding」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 innonazarene/prism-init 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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