ldc-web/app/Http/Resources/Api/LDCNetworkResource.php
2022-06-15 13:43:05 +02:00

31 lines
1,010 B
PHP

<?php
namespace App\Http\Resources\Api;
use App\Models\LDCNetwork;
use Illuminate\Http\Resources\Json\ResourceCollection as JsonResourceCollection;
class LDCNetworkResource extends JsonResourceCollection
{
/**
* Transform the resource into an array.
*
* @param mixed $request
* @return array
*/
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass, Squiz.Commenting.FunctionComment.Missing
public function toArray($request)
{
return $this->collection->map(function (LDCNetwork $network) {
$infos = collect(explode('.', strval($network->first_ip)));
$min = intval($infos->get(3));
$max = collect(explode('.', strval($network->last_ip)))->get(3);
for ($i = $min; $i <= $max; $i++) {
$ips[] = $infos->get(0) . '.' .
$infos->get(1) . '.' .
$infos->get(2) . ".$i";
}
return $ips;
});
}
}