2018-01-24 11:40:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
2019-07-16 03:14:40 +08:00
|
|
|
use App\Interfaces\Unit;
|
2018-01-24 11:40:34 +08:00
|
|
|
use Illuminate\Http\Resources\Json\Resource;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Response
|
|
|
|
*/
|
|
|
|
class Response extends Resource
|
|
|
|
{
|
2019-07-16 03:14:40 +08:00
|
|
|
/**
|
|
|
|
* 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};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-24 11:40:34 +08:00
|
|
|
}
|