#3 laravel-magic-rest

Universal REST contoller for CRUD operations with dynamic routes and support for file uploads.

Universal REST contoller for CRUD operations with dynamic routes and support for file uploads.

Each route returns JSON. Example of routes wich will be available automatically:

GET     /rest/rest/book    get list of AppBooks models
POST    /rest/rest/book    create new book

GET     /rest/book/[id]   returns single book
POST    /rest/book/[id]   updates book
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       attach or detach already existed athor to
                                       book. This method accepts "attach" and
                                       "detach" query parameters with array of ids.

GET     /rest/book/[id]/description    returns value of field
DELETE  /rest/book/[id]/field          remove uploaded file / empty field
POST    /rest/book/[id]/field          updates model "field" from POST "value" argument 
                                       or uploads file from "file" POST field if it is existed.

Installation

Simply do:

composer require ont/laravel-magic-rest

and then add service provider to config/app.php

    <?php
        'providers' => array(
            ...
            'OntMagicRestServiceProvider',
            ...
        ),
    ?>

If you need change default route prefix /rest to something else then you must execute php artisan vendor:publish and edit config/magic-rest.php

 

 

License

MIT

Links