ont/laravel-magic-rest
最新稳定版本:0.0.6-alpha
Composer 安装命令:
composer require ont/laravel-magic-rest
包简介
Universal REST contoller for CRUD operations with dynamic routes and support for file uploads.
README 文档
README
Description
This laravel module generates on-the-fly routes for CRUD operations for defined models and relations. All generated routes are REST-like and also support some non-CRUD operations such as model field updating and file uploading.
Let us have this database structure:
<?php
class Author extends Model
{
public function books() {
return $this->belongsToMany('App\Book');
}
}
class Book extends Model
{
public function author() {
return $this->belongsToMany('App\Author');
}
}
Then these routes will be generated automatically:
GET /rest/book get list of App\Books models
POST /rest/book create new book
GET /rest/book/[id] returns single book
PUT /rest/book/[id] updates book from json
DELETE /rest/book/[id] delete book
GET /rest/book/[id]/authors get list of authors
GET /rest/book/[id]/authors/[id] get single author
POST /rest/book/[id]/relation create new related model from json and
attach it to book with [id]. Returns
json of created model.
PUT /rest/book/[id]/authors updates authors from json field "value"
For example you can POST this json:
{ value: [
{ 'id': 123, 'name': 'James' },
{ 'name': 'John' },
]}
After this magic rest will create new author with name 'John', will update
old author's name with 'id' 123 and remove all another authors from relation.
Returns json of updated relation.
For one-to-one relation you must send object {value: {id:123}}
For one-to-many and many-to-many you must send list {value: [{id:1}, {id:2},...]}
GET /rest/book/[id]/description returns value of field "description"
DELETE /rest/book/[id]/another_field removes uploaded file / empty field
POST /rest/book/[id]/field can update model "field" from different sources:
1) directly from POST json "value" field
2) upload file from POST "file" field and save path into "field"
2) upload file from POST json "base64" field (file content in base64)
and "name" json field (original filename) and save uploaded path to "field"
Installation
Simply do:
composer require ont/laravel-magic-rest
and then add service provider to `config/app.php`
<?php
'providers' => array(
...
'Ont\MagicRest\ServiceProvider',
...
),
?>
If you need change default route prefix `/restto something else then
you must executephp artisan vendor:publishand editconfig/magic-rest.php`
TODO
- change POST to PUT for field processor (it doesn't create anything)
- remove "value" from PUT request for relation processor
- update major version (backward incompatible changes)
- better documentation
- access permissions from laravel
- add docs about file uploader optional dependency
ont/laravel-magic-rest 适用场景与选型建议
ont/laravel-magic-rest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.05k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「routing」 「rest」 「upload」 「crud」 「laravel」 「automatic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ont/laravel-magic-rest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ont/laravel-magic-rest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ont/laravel-magic-rest 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Write down your routing mapping at one place
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.
Laravel Media Popup to upload/view the files
统计信息
- 总下载量: 1.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-10