LaravelPackages.net
Acme Inc.
Toggle sidebar
viralsbackpack/backpackapi

CRUD Api in Backpack

110
4
1.0
About viralsbackpack/backpackapi

viralsbackpack/backpackapi is a Laravel package for crud api in backpack. It currently has 4 GitHub stars and 110 downloads on Packagist (latest version 1.0). Install it with composer require viralsbackpack/backpackapi. Discover more Laravel packages by viralsbackpack or browse all Laravel packages to compare alternatives.

Last updated

BackPackAPI

Latest Version on Packagist Total Downloads Build Status StyleCI

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';
    }
]);

Output: alt text

_Set up extra data

<?php

$this->crud->setExtraData([
    'test' => 123
]);

Output: alt text

_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

License

license. Please see the license file for more information.

Star History Chart