PHP code example of lassehaslev / api-response

1. Go to this page and download the library: Download lassehaslev/api-response 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/ */

    

lassehaslev / api-response example snippets

$this->response
$response->item()
$response->collection()
 php
use LasseHaslev\ApiResponse\Responses\ResponseTrait;
class ResponseCaller
{
    use ResponseTrait;

    public function getItem() {
        return $this->response->item( [ 'name'=>'Test name' ], new Transformer );
    }

    public function getCollection() {
        return $this->response->collection( [
            [ 'name'=>'Test name' ],
            [ 'name'=>'Another test name' ]
        ], new Transformer );
    }

}
array
public function 
/api/request?
 php
use LasseHaslev\ApiResponse\Transformers\Transformer as BaseTransformer;
class Transformer extends BaseTransformer
{

    protected $defaultIncludes = [ 'default' ];
    protected $availableIncludes = [ 'available' ];

    /**
     * Transform $model
     *
     * @return Array
     */
    public function transform( $model )
    {
        return [
            'name'=>$model[ 'name' ],
        ];
    }

    /**
     * Return