PHP code example of viralsbackpack / backpackapi

1. Go to this page and download the library: Download viralsbackpack/backpackapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

viralsbackpack / backpackapi example snippets




$this->setRequestStoreApi(StoreRequest::class);
$this->setRequestUpdateApi(UpdateRequest::class);




// Set up structure of data in response
$this->crud->setResponse([
    'id', 'name'  //fields of its model
]);



$this->crud->setResponse([
    'name' => function($entry) {
        return $entry->name . '123';
    },
    'id' => function($entry) {
        return $entry->id . '123';
    }
]);




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




$this->crud->setDeleteReturnList(true);




$this->crud->setMessage('message');




$this->crud->setStatus(123);

bash
php artisan backpack:crud-api-controller Name