Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
tipuloidea
/
back
/
app
/
Http
/
Resources
:
CashFlowCreditResource.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php namespace App\Http\Resources; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class CashFlowCreditResource extends JsonResource { public function toArray(Request $request): array { $totalCredit = 0; $totalCash = 0; foreach ($this->paymentDistributions as $distribution) { $amount = (float)$distribution->amount; if (isset($distribution->article->article_type)) { if ($distribution->article->article_type === 'credit') { if (isset($distribution->article_id) && $distribution->article_id == 1) { $totalCash += $amount; } else { $totalCredit += $amount; } } } } return [ 'id' => $this->id, 'name' => $this->name, 'default_in_project' => $this->default_in_project, 'model_id' => $this->model_id, 'total_amount' => $totalCredit, 'total_cash' => $totalCash, 'sort' => $this->sort, 'group' => [ 'id' => $this->group->id, 'name' => $this->group->name, 'model_id' => $this->group->model_id, ] ]; } }