1
Ich habe ein Problem, konstanten Wert mit übergeordneten Tabelle Wert in Beziehungstabelle zu verwenden.Laravel 5.4 arithmetische Operation in Modellbeziehung
$cost = 5;
$product = Product::with(["productPrice" => function($q) use($cost) {
$q->select("id", "product_id", "price", \DB::Raw("(('"+ $cost + "' * product.weight)/product.pack_size) + price as cost"));
}])->select("id", "sku", "pack_size", "image" ,'weight')->get();
in Mysql,
select product.id, product.sku, product.pack_size, product.image, product.weight, product_price.id as product_price_id, product_price.price,(($cost * product.weight)/product.pack_size) + product_price.price as cost from product join product_price on product.id = product_price.product_id
Abfrage arbeiten bereit, aber wie in Laravel Modell Beziehung zu bedienen?
Problem gelöst Verwenden des Abfrage-Generators, aber wie Sie Lösungen mithilfe der eloquenten Beziehung erhalten. Irgendeine Idee? –