Files
freeu-project/app/Http/Resources/CleanAndGreenAssetsResource.php
2024-04-12 15:07:34 +05:30

51 lines
1.7 KiB
PHP

<?php
namespace App\Http\Resources;
use App\Models\Product;
use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\ProductImage;
class CleanAndGreenAssetsResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$products = Product::find($this->products_id);
$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' => $products->presentation ?? null,
'fact_sheet' => $products->fact_sheet ?? null,
'project_name' => $this->project_name,
'slug' => $this->slug,
'focus_area' => $this->focus_area,
'asset_value' => $this->asset_value,
'asset_life' => $this->asset_life,
'entry_load' => $this->entry_load,
'lockin_period' => $this->lockin_period,
'minimum_investment' => $this->minimum_investment,
'maximum_investment' => $this->maximum_investment,
'expected_returns_irr' => $this->expected_returns_irr,
'payouts' => $this->payouts,
'minimum_investment_in_int' => $this->minimum_investment_in_int
];
}
}