mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-21 05:23:58 +00:00
29 lines
1013 B
PHP
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())
|
|
];
|
|
});
|
|
}
|
|
} |