129 - Total Revenue and a Relationship Bug

This commit is contained in:
Adam Wathan
2017-07-19 16:01:48 -04:00
parent f3a38b7cc2
commit 9923d23bc3
3 changed files with 19 additions and 3 deletions

View File

@@ -48,7 +48,7 @@ class Concert extends Model
public function orders()
{
return $this->belongsToMany(Order::class, 'tickets');
return Order::whereIn('id', $this->tickets()->pluck('order_id'));
}
public function hasOrderFor($customerEmail)
@@ -114,4 +114,9 @@ class Concert extends Model
{
return number_format(($this->ticketsSold() / $this->totalTickets()) * 100, 2);
}
public function revenueInDollars()
{
return $this->orders()->sum('amount') / 100;
}
}