PHP code example of chenyansong / response-transformation

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

    

chenyansong / response-transformation example snippets


namespace App\Transformation;


use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Wdnmd\Transform;

class UserTransform extends Transform
{
    protected $modelName = ['type'];

    protected $modelTransForm = ['type' => TypeTransform::class];

    public function handle(Model $user) {
        return [
            'name' => $user->name
        ];
    }

    public function installType($user)
    {
        return $this->item($user->getType, new TypeTransform());
    }
}
shell
    php artisan wdnmd:publish