PHP Classes

File: server/app/Transformers/UserTransformer.php

Recommend this page to a friend!
  Classes of mohammad anzawi   PHP Wallet API and Application   server/app/Transformers/UserTransformer.php   Download  
File: server/app/Transformers/UserTransformer.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Wallet API and Application
Application to manage a wallet by calling an API
Author: By
Last change:
Date: 2 years ago
Size: 946 bytes
 

Contents

Class file image Download
<?php

namespace App\Transformers;

use
App\Models\User;
use
App\Models\Wallet;
use
League\Fractal\TransformerAbstract;

class
UserTransformer extends TransformerAbstract
{

    private
$_token;
    public function
__construct(string $token = null)
    {
       
$this->_token = $token;
    }

   
/**
     * List of resources possible to include
     *
     * @var array
     */
   
protected $availableIncludes = [
       
'wallet'
   
];
   
/**
     * A Fractal transformer.
     *
     * @return array
     */
   
public function transform(User $user)
    {
        return [
           
'name' => $user->name,
           
'email' => $user->email,
           
'blocked' => $user->isBlocked,
           
'is_admin' => (bool)$user->is_admin,
           
'token' => $this->_token
       
];
    }

    public function
includeWallet(User $user)
    {
            return
$this->item($user->wallet?? new Wallet(), new WalletTransformer());
    }
}