Files
exchange-2.0/app/Classes/Modules/Companies/Services/FetchesCompanyServices.php
T
omair saleh 05401f6bbc large commit
2021-03-11 13:06:40 +08:00

29 lines
1013 B
PHP

<?php
namespace App\Classes\Modules\Companies\Services;
use App\Http\Resources\CurrencyResource;
use App\Models\Currency;
use Illuminate\Support\Collection;
class FetchesCompanyServices
{
public function getServices(Collection $services){
return $services->map(function($service){
$currencies = collect($service->getConfigurations()->detail->currencies)->pluck('id');
if(!empty($service->getCustomOptions())){
$currencies = $currencies->merge(collect($service->getCustomOptions())->flatMap(function($configurations){
return collect($configurations->getConfigurationValue('currencies'))->pluck('id');
}));
}
return [
'id' => $service->getService()->id,
'name' => $service->getService()->name,
'currencies' => CurrencyResource::collection(Currency::whereIn('id', $currencies->filter()->unique()->toArray())->get())
];
});
}
}