ont/laravel-magic-rest 问题修复 & 功能扩展

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

邮箱: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

统计信息

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

GitHub 信息

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

其他信息

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