viralsbackpack/backpackapi
Composer 安装命令:
composer require viralsbackpack/backpackapi
包简介
CRUD Api in Backpack
关键字:
README 文档
README
Quickly build an api interface for your Eloquent models, using Laravel 5. Erect a complete CMS at 10 minutes/model, max.
Features:
- Crud and search call api
- Back-end validation using Requests
- Easily overwrite functionality (customising how the create/update/delete process works is as easy as creating a new function with the proper name in your EntityCrudAPICrontroller)
Installation
composer require viralsbackpack/backpackapi
Setup
1. Command
_Create controller and add route for api:
php artisan backpack:crud-api name
This command will create NameAPICrudController in folder app/Http/Api and add route api route resource in routes/backpack/api.php
or particular command
_Create controller:
php artisan backpack:crud-api-controller Name
_Add route for api:
php artisan backpack-api:add-custom-route "BackPackAPI::resource('name', 'NameCrudAPIController');"
2. Setup api
All the settings below can be added to any method in the controller.
_Add validate request:
<?php $this->setRequestStoreApi(StoreRequest::class); $this->setRequestUpdateApi(UpdateRequest::class);
_Setup structure data in response
<?php // Set up structure of data in response $this->crud->setResponse([ 'id', 'name' //fields of its model ]);
or custom fields
<?php $this->crud->setResponse([ 'name' => function($entry) { return $entry->name . '123'; }, 'id' => function($entry) { return $entry->id . '123'; } ]);
_Set up extra data
<?php $this->crud->setExtraData([ 'test' => 123 ]);
_Set up return list entries after delete:
<?php $this->crud->setDeleteReturnList(true);
_Set message:
<?php $this->crud->setMessage('message');
_Set status:
<?php $this->crud->setStatus(123);
Usage
| Method | URI | Name | Action | Parameter obligatory | Form data obligatory |
|---|---|---|---|---|---|
| GET/HEAD | api/name | crud-api.name.index | App\Http\Controllers\Api\NameCrudAPIController@index | ||
| POST | api/name | crud-api.name.store | App\Http\Controllers\Api\NameCrudAPIController@store | ||
| POST | api/name/search | crud-api.name.search | App\Http\Controllers\Api\TagCrudAPIController@search | search[value] | |
| GET/HEAD | api/name/{id} | crud-api.name.show | App\Http\Controllers\Api\NameCrudAPIController@show | id | |
| PUT/PATCH | api/name/{id} | crud-api.name.update | App\Http\Controllers\Api\NameCrudAPIController@update | id | _method = PUT ; id |
| DELETE | api/name/{id} | crud-api.name.destroy | App\Http\Controllers\Api\NameCrudAPIController@destroy | id | _method = DELETE |
Credits
- [author name][manhhd@viralsoft.vn]
License
license. Please see the license file for more information.
统计信息
- 总下载量: 110
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-25

