AB
Size: a a a
AB
AH
AB
$request->all()['currencyType']бляяяяя
$request->get('currencyType')
для кого придумали?D
AH
D
AB
AB
AH
D
AB
AH
AB
D
AB
AB
AH
$newVariation = new ProductVariationResource(ProductVariation::where('id', $product['productVariation']['id'])->first());
ресурсpublic function toArray($request)
{
$price = $this->product_stores()->first()->price ?? 0;
$prices = Money::getConvertPrice($request->all()['currencyType'], $price);
return [
'id' => $this->id,
'name_fstek' => $this->name_fstek,
'weight' => $this->weight,
'length' => $this->length,
'width' => $this->width,
'height' => $this->height,
'price' => $prices['price'],
'price_string' => $prices['price_string'],
'product_id' => $this->product_id,
// 'product_store' => new ProductStore($this->product_stores->first()),
'product_items' => new ProductItems($this->items->first()),
];
}
// controller
class ProductVariationController extends Controller
{
public function index(ProductVariation $variation)
{
return ProductVariationResource::make($variation);
}
}
// resource
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class ProductVariationResource extends JsonResource
{
public function toArray($request)
{
$prices = $this->prices($request);
return [
'id' => $this->id,
'name_fstek' => $this->name_fstek,
'weight' => $this->weight,
'length' => $this->length,
'width' => $this->width,
'height' => $this->height,
'price' => Arr::get($prices, 'price'),
'price_string' => Arr::get($prices, 'price_string'),
'product_id' => $this->product_id,
'product_items' => ProductItemResource::collection($this->items),
];
}
protected function price(): int
{
return $this->product_stores()->first()->price ?? 0;
}
protected function prices($request): array
{
return Money::getConvertPrice($request->get('currencyType'), $this->price());
}
}
AB
// controller
class ProductVariationController extends Controller
{
public function index(ProductVariation $variation)
{
return ProductVariationResource::make($variation);
}
}
// resource
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Arr;
class ProductVariationResource extends JsonResource
{
public function toArray($request)
{
$prices = $this->prices($request);
return [
'id' => $this->id,
'name_fstek' => $this->name_fstek,
'weight' => $this->weight,
'length' => $this->length,
'width' => $this->width,
'height' => $this->height,
'price' => Arr::get($prices, 'price'),
'price_string' => Arr::get($prices, 'price_string'),
'product_id' => $this->product_id,
'product_items' => ProductItemResource::collection($this->items),
];
}
protected function price(): int
{
return $this->product_stores()->first()->price ?? 0;
}
protected function prices($request): array
{
return Money::getConvertPrice($request->get('currencyType'), $this->price());
}
}
AH
AB