'decimal:2', 'cost' => 'decimal:2', 'profit_margin' => 'decimal:4' ]; // Relationships public function order(): BelongsTo { return $this->belongsTo(Order::class); } // Calculate profit amount public function getProfitAttribute() { return $this->amount - $this->cost; } // Calculate profit margin percentage public function getProfitMarginPercentageAttribute() { if ($this->amount > 0) { return (($this->amount - $this->cost) / $this->amount) * 100; } return 0; } // Scope for today's revenue public function scopeToday($query) { return $query->whereDate('created_at', today()); } // Scope for date range public function scopeDateRange($query, $startDate, $endDate) { return $query->whereBetween('created_at', [$startDate, $endDate]); } }