viralsbackpack / backpackapi
CRUD Api in Backpack
Requires
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ~3.0
- phpunit/phpunit: ~7.0
- sempro/phpunit-pretty-print: ^1.0
This package is auto-updated.
Last update: 2025-02-26 04:06:36 UTC
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.