belongsTo(Invoice::class); } public function order(): BelongsToThrough { return $this->belongsToThrough(Order::class, Invoice::class); } public function scopeByInvoice($query, $invoiceId) { return $query->where('invoice_id', $invoiceId); } public function scopeValidated($query) { return $query->where('validated', 1); } public function scopeByOrder($query, $orderId) { return $query->whereHas('order', function ($query) use ($orderId) { return $query->byOrder($orderId); }); } public function scopeByPaymentType($query, $paymentType) { return $query->where('payment_type', $paymentType); } }