Files
freeu-project/app/Http/Resources/HighYieldFinanceResource.php
2024-04-30 11:02:34 +05:30

56 lines
2.0 KiB
PHP

<?php
namespace App\Http\Resources;
use App\Models\Product;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\ProductImage;
class HighYieldFinanceResource 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 parent::toArray($request);
return [
'id' => $this->id,
'products_id' => $this->products_id,
'product_images' => $imagePaths,
'presentation' => Product::where('id',$this->products_id)->value('presentation'),
'fact_sheet' => Product::where('id',$this->products_id)->value('fact_sheet'),
'slug' => $this->slug,
'security_name' => $this->security_name,
'security_type' => $this->security_type,
'isin' => $this->isin,
'issuer_company' => $this->issuer_company,
'issue_size' => $this->issue_size,
'issue_type' => $this->issue_type,
'listing_details' => $this->listing_details,
'rating_category' => $this->rating_category,
'minimum_investment' => $this->minimum_investment,
'coupon_rate' => $this->coupon_rate,
'yield_to_maturity' => $this->yield_to_maturity,
'interest_payment_frequency' => $this->interest_payment_frequency,
'allotment_date' => $this->allotment_date,
'maturity_date' => $this->maturity_date,
'minimum_investment_in_int' => $this->minimum_investment_in_int,
];
}
}