PHP code example of divspace / responder

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

    

divspace / responder example snippets


'providers' => array(
    // ...
    'Divspace\Responder\ResponderServiceProvider'
)

use Divspace\Responder\Responder;
use Data\Transformers\UserTransformer;

class UserController extends BaseController {
    protected $response;

    public function __construct(Responder $response) {
        $this->response = $response;

        /**
         * Fractal parseIncludes() method
         * http://fractal.thephpleague.com/transformers/
         */
        if(isset($_GET['ansformer());
    }

    /**
     * Display all users
     */
    public function collection() {
        return $this->response->collection(User::all(), new UserTransformer());
    }
}

 namespace Data\Transformers;

use User;
use League\Fractal\TransformerAbstract;

class UserTransformer extends TransformerAbstract {

    protected $defaultIncludes = [
        'user_type'
    ];

    public function transform(User $user) {
        $user = User::find($user->id);

        return [
            'id'         => (int) $user->id,
            'email'      => $user->email,
            'created_at' => $user->created_at,
            'updated_at' => $user->updated_at,
        ];
    }

    public function 

 namespace Data\Transformers;

use User;
use League\Fractal\TransformerAbstract;

class UserTypeTransformer extends TransformerAbstract {

    public function transform($userType) {
        if(count($userType) > 0) {
            return [
                'id'   => (int) $userType->id,
                'name' => $userType->name
            ];
        }

        return [];
    }

}