*/ public $fillable = ['member_id', 'invoice_data', 'subscription_id', 'nr', 'status_id', 'last_remembered_at']; /** * @var array */ public $casts = [ 'invoice_data' => 'json', 'last_remembered_at' => 'date', ]; /** * @return BelongsTo */ public function member(): BelongsTo { return $this->belongsTo(Member::class); } /** * @return BelongsTo */ public function subscription(): BelongsTo { return $this->belongsTo(Subscription::class); } /** * @return BelongsTo */ public function status(): BelongsTo { return $this->belongsTo(Status::class); } /** * @param Builder $query * * @return Builder */ public function scopeWhereNeedsPayment(Builder $query): Builder { return $query->whereHas('status', function ($q) { return $q->needsPayment(); }); } /** * @param Builder $query * * @return Builder */ public function scopeWhereNeedsBill(Builder $query): Builder { return $query->whereHas('status', function ($q) { return $q->where('is_bill', true); }); } /** * @param Builder $query * * @return Builder */ public function scopeWhereNeedsRemember(Builder $query): Builder { return $query->whereHas('status', function ($q) { return $q->where('is_remember', true); })->where(fn ($query) => $query->whereNull('last_remembered_at')->orWhere('last_remembered_at', '<=', now()->subMonths(3))); } }