chriskelemba/auto-crud
Composer 安装命令:
composer require chriskelemba/auto-crud
包简介
A Laravel package providing base controller with CRUD and file operations
关键字:
README 文档
README
Auto Crud is a Laravel package that gives you fully functional CRUD for both API and Web routes — with just an empty controller.
No routes file changes.
No repetitive controller methods.
No resource classes required (but supported).
Just extend one class → instant CRUD.
Features
- 100% automatic CRUD (index, show, store, update, destroy)
- JSON:API-style responses by default
- Configurable response formatter (no controller edits required)
- Soft delete support (trashed, restore, force-delete)
- Built-in file management (single + multiple upload, download, replace)
- Automatic model & resource detection using naming conventions
- Laravel Resource class integration (if exists)
- Works with standard
app/Http/Controllersand modular structure (app/Modules/*) - Automatic route registration under /api and/or web routes
- Validation rules, eager loading, ordering — all customizable with protected properties
Installation
composer require chriskelemba/api-auto-crud
This package ships with a JSON:API-style response format by default, and lets you override it without touching controllers.
Usage
All you require to do is to extend the package's controller file.
<?php namespace App\Http\Controllers; use AutoCrud\Http\Controllers\Controller; class UserController extends Controller { // }
Auto-Generated CRUD Routes
For every controller that extends AutoCrud\Http\Controllers\Controller, the package automatically registers a full CRUD route set under the API prefix, and optionally under Web routes.
Assuming a controller named:
<?php namespace App\Http\Controllers; use AutoCrud\Http\Controllers\Controller; class UserController extends Controller { // }
The base API route becomes:
/api/users
Below are the complete routing tables generated for every auto-CRUD controller:
## Standard CRUD Routes | Method | URI | Action | Route Name | |--------|---------------------|----------|-----------------| | GET | /api/users | index | users.index | | POST | /api/users | store | users.store | | GET | /api/users/{id} | show | users.show | | PUT | /api/users/{id} | update | users.update | | DELETE | /api/users/{id} | destroy | users.destroy | ## Soft Delete Routes (Only active if the model uses SoftDeletes) | Method | URI | Action | Route Name | |--------|-------------------------------|--------------|--------------------| | GET | /api/users/trashed | trashed | users.trashed | | POST | /api/users/{id}/restore | restore | users.restore | | DELETE | /api/users/{id}/force | forceDelete | users.forceDelete | ## File Handling Routes | Method | URI | Action | Route Name | |--------|------------------------------------|---------------------|-------------------------| | POST | /api/users/upload | uploadFile | users.upload | | POST | /api/users/{id}/upload | updateFile | users.updateFile | | POST | /api/users/uploads/multiple | uploadMultiple | users.uploadMultiple | | GET | /api/users/download/{id} | downloadFile | users.download | | DELETE | /api/users/delete-file/{id} | users.deleteFile | deleteFile |
Web Routes (optional)
If you enable web routes, the same endpoints are registered under the web prefix:
/users
The route names are prefixed with web. by default:
| Method | URI | Action | Route Name | |--------|---------------------|----------|-----------------| | GET | /users | index | web.users.index | | POST | /users | store | web.users.store | | GET | /users/{id} | show | web.users.show | | PUT | /users/{id} | update | web.users.update| | DELETE | /users/{id} | destroy | web.users.destroy|
⚠️ Model Requirement
This package requires every controller to be provided with a model. If the model is not defined, the controller cannot perform CRUD, soft delete, or file handling operations. Make sure your configuration specifies the model used by each controller.
Custom JSON Responses (No Controller Changes)
AutoCrud returns a JSON:API-style payload by default (including pagination links/meta):
{
"data": [],
"meta": {
"message": "Users fetched successfully.",
"pagination": {
"current_page": 1,
"from": 1,
"last_page": 10,
"per_page": 10,
"to": 10,
"total": 100
}
},
"links": {
"first": "https://example.test/api/users?page=1",
"last": "https://example.test/api/users?page=10",
"prev": null,
"next": "https://example.test/api/users?page=2"
}
}
Customize the response without editing controllers
Create a formatter class in your app:
<?php namespace App\Support; class ApiResponseFormatter { public function success($data = null, string $message = 'OK', int $code = 200) { return response()->json([ 'data' => $data, 'meta' => ['message' => $message], ], $code); } public function error(string $message = 'Error', int $code = 400, $errors = null) { return response()->json([ 'errors' => [[ 'status' => (string) $code, 'detail' => $message, 'meta' => ['errors' => $errors], ]], ], $code); } }
Then update your published config:
// config/autocrud.php 'response_formatter' => \App\Support\ApiResponseFormatter::class,
Default per-page size
The index endpoint paginates by default (10 per page). You can change it:
AUTOCRUD_API_PER_PAGE=10
Configuration (via .env)
You can configure AutoCrud using environment variables (no config publish required):
Example .env
AUTOCRUD_API_ENABLED=true
AUTOCRUD_API_PREFIX=api
AUTOCRUD_API_ROUTE_PREFIX=
AUTOCRUD_API_PER_PAGE=10
AUTOCRUD_WEB_ENABLED=false
AUTOCRUD_WEB_PREFIX=
AUTOCRUD_WEB_ROUTE_PREFIX=web.
Optional: you can still publish the config if you want to hard‑code settings:
php artisan vendor:publish --tag=autocrud-config
Requirements
- Laravel 12
- PHP 8.2+
Contributing
Contributions are open to everyone.
Feel free to submit issues, feature requests, or pull requests.
License
This package is open-source software licensed under the MIT License.
chriskelemba/auto-crud 适用场景与选型建议
chriskelemba/auto-crud 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「controller」 「crud」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chriskelemba/auto-crud 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chriskelemba/auto-crud 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chriskelemba/auto-crud 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Give your JS App some Backbone with Models, Views, Collections, and Events.
Gii Generator for double model generation
A PSR-7 compatible library for making CRUD API endpoints
Admin panel generator for Laravel 8 and based on Vuetify Admin, a separate SPA admin framework running on top of REST APIs.
Collection of tools to use the full power of the Enyalius framework
Create mail from controller action render
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-03
