PHP code example of liyu / dingo-serializer-switch

1. Go to this page and download the library: Download liyu/dingo-serializer-switch 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/ */

    

liyu / dingo-serializer-switch example snippets


$app->routeMiddleware([
    // ...
    'serializer' => Liyu\Dingo\SerializerSwitch::class,
]);

$api->version('v1',
    ['middleware' => 'serializer:array'],
    function ($api) {
});

$api->version('v2',
    ['middleware' => 'serializer'],
    function ($api) {
});

$api->version('v3',
    ['middleware' => 'serializer:data_array'],
    function ($api) {
});

'default_array' => 'League\Fractal\Serializer\ArraySerializer',
'default_data_array' => 'League\Fractal\Serializer\DataArraySerializer',
'json_api' => 'League\Fractal\Serializer\JsonApiSerializer',

'array' => 'Liyu\Dingo\Serializers\ArraySerializer',
'data_array' => 'Liyu\Dingo\Serializers\DataArraySerializer',