Files
freeu-project/app/Http/Resources/GlobalFundResource.php
Ritikesh yadav 5d8a8f6bbc fixed changes
2024-06-20 15:04:59 +05:30

59 lines
2.2 KiB
PHP

<?php
namespace App\Http\Resources;
use App\Models\Product;
use App\Models\ProductImage;
use Illuminate\Http\Resources\Json\JsonResource;
class GlobalFundResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$images = ProductImage::where('product_xid', $this->products_id)->get();
$imagePaths = [];
if (!empty($images)) {
foreach ($images as $imageItem) {
$path = asset('public/' . $imageItem['images']);
$imagePaths[] = $path;
}
}
return [
'id' => $this->id,
'products_id' => $this->products_id,
'product_images' => $imagePaths,
'presentation' => Product::find($this->products_id) ? Product::where('id',$this->products_id)->value('presentation') : null,
'fact_sheet' => Product::find($this->products_id) ? Product::where('id',$this->products_id)->value('fact_sheet') : null,
'slug' => $this->slug,
'issuer' => $this->issuer,
'fund_name' => $this->fund_name,
'fund_type' => $this->fund_type,
'about_issuer' => $this->about_issuer,
'fund_description' => $this->fund_description,
'sharpe_ratio' => $this->sharpe_ratio,
'annualized_volatility' => $this->annualized_volatility,
'max_dropdown' => $this->max_dropdown,
'isin' => $this->isin,
'inception_date' => $this->inception_date,
'fund_aum' => $this->fund_aum,
'expense_ratio' => $this->expense_ratio,
'nav_per_unit' => $this->nav_per_unit,
'minimum_investment' => $this->minimum_investment,
'ytd' => $this->ytd,
'year1_return' => $this->year1_return,
'year3_return' => $this->year3_return,
'returns' => $this->returns,
'date_as_on' => $this->date_as_on,
// 'product_images' => ProductImage::where('product_xid',$this->products_id)->get(),
];
}
}