array_column($order->toArray(), 'product') // Rezultat "id" => 1 "name" => "Fitness tracker" "price" => 75.99 "created_at" => "2018-11-30 13:15:18" "updated_at" => "2019-01-16 20:59:21" ] ]
array_column($order->toArray(), 'product') // Rezultat "id" => 1 "name" => "Fitness tracker" "price" => 75.99 "created_at" => "2018-11-30 13:15:18" "updated_at" => "2019-01-16 20:59:21" ] ]
// Rezultat // Rezultat int(0)
Collection {#638 ▼ #items: array:2 [▼ 0 => Order {#634 ▼ #table: "orders" #fillable: array:6 [▶] #connection: "mysql" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:9 [▶] #original: array:9 [▶] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: array:1 [▼ "product" => Product {#673 ▼ #connection: "mysql" #table: "products" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:12 [▼ "id" => 1 "Name" => "Fitness tracker" "price" => 75.99 "created_at" => "2018-11-30 13:15:18" "updated_at" => "2019-01-16 20:59:21" ] #original: array:12 [▶] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #hidden: [] #visible: [] #fillable: [] #guarded: array:1 [▶] } ] #touches: [] +timestamps: true #hidden: [] #visible: [] #guarded: array:1 [▶] } 1 => Order {#635 ▶} ] }
Order::with('product')->where('id', $id)->get()->sum('product.price');
$this->products->sum('price');
$total = Order::with('product')->where('id', $id)->get()->sum('product.price');
Order::with('product')->where('id', $id)->get();