Edit File: GroupResource.php
<?php namespace App\Http\Resources; use Carbon\Carbon; use Illuminate\Http\Resources\Json\JsonResource; class GroupResource extends JsonResource { /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { $price=0; if($this->discount_price && \Carbon\Carbon::parse(now())->toDateString() >= $this->from && \Carbon\Carbon::parse(now())->toDateString() < $this->to ){ $price=$this->discount_price; }else{ $price= $this->price; } return [ 'id' => $this->id, 'price' => $this->price()? (string) $this->price() : '0', 'qty' => $this->in_stock_qty? ( $this->in_stock_qty - ($this->orderproducts()->whereDate('created_at' , Carbon::today())->sum('qty')) ) : 0, ]; } }
Back to File Manager