定制 ont/laravel-magic-rest 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

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

  1. change POST to PUT for field processor (it doesn't create anything)
  2. remove "value" from PUT request for relation processor
  3. update major version (backward incompatible changes)
  4. better documentation
  5. access permissions from laravel
  6. 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 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-10