PHP Classes

File: server/app/Transformers/WalletTransformer.php

Recommend this page to a friend!
  Classes of mohammad anzawi   PHP Wallet API and Application   server/app/Transformers/WalletTransformer.php   Download  
File: server/app/Transformers/WalletTransformer.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: 978 bytes
 

Contents

Class file image Download
<?php

namespace App\Transformers;

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

class
WalletTransformer extends TransformerAbstract
{
   
/**
     * List of resources possible to include
     *
     * @var array
     */
   
protected $availableIncludes = [
       
'transaction',
       
'user'
   
];

   
/**
     * A Fractal transformer.
     *
     * @return array
     */
   
public function transform(Wallet $wallet)
    {
        return [
           
'name' => $wallet->name,
           
'withdraw' => $wallet->withdraw(),
           
'deposit' => $wallet->deposit(),
           
'balance' => $wallet->balance(),
           
'uuid' => $wallet->uuid
       
];
    }

    public function
includeTransaction(Wallet $wallet)
    {
        return
$this->collection($wallet->transactions, new TransactionsTransformer());
    }

    public function
includeUser(Wallet $wallet)
    {
        return
$this->item($wallet->user, new UserTransformer());
    }
}