Created
October 20, 2015 14:02
-
-
Save korrio/ec3680af95f98afec000 to your computer and use it in GitHub Desktop.
Order Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Order | |
extends Eloquent | |
{ | |
protected $table = "order"; | |
protected $guarded = ["id"]; | |
protected $softDelete = true; | |
public function account() | |
{ | |
return $this->belongsTo("Account"); | |
} | |
public function orderItems() | |
{ | |
return $this->hasMany("OrderItem"); | |
} | |
public function products() | |
{ | |
return $this->belongsToMany("Product", "order_item"); | |
} | |
public function getTotalAttribute() | |
{ | |
$total = 0; | |
foreach ($this->orderItems as $orderItem) | |
{ | |
$total += $orderItem->price * $orderItem->quantity; | |
} | |
return $total; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment