phpvms/app/Contracts/Resource.php
Nabeel S 9e5386264f
SimBrief integration #405 (#635)
* SimBrief integration #405

* Add briefing as API response; add acars_xml field #405
2020-03-23 09:31:35 -04:00

28 lines
660 B
PHP

<?php
namespace App\Contracts;
/**
* Base class for a resource/response
*/
class Resource extends \Illuminate\Http\Resources\Json\Resource
{
/**
* Iterate through the list of $fields and check if they're a "Unit"
* If they are, then add the response
*
* @param $response
* @param array $fields
*/
public function checkUnitFields(&$response, array $fields): void
{
foreach ($fields as $f) {
if ($this->{$f} instanceof Unit) {
$response[$f] = $this->{$f}->getResponseUnits();
} else {
$response[$f] = $this->{$f};
}
}
}
}