Add status attribute to Recurring model
MODIFY
app/Recurring.php
app/Recurring.php
@@ -23,6 +23,10 @@ class Recurring extends Model {
return 0;
}
+ public function getStatusAttribute() {
+ return $this->starts_on <= date('Y-m-d') && ($this->ends_on >= date('Y-m-d') || !$this->ends_on);
+ }
+
// Relations
public function spendings() {
return $this->hasMany(Spending::class);

MODIFY
resources/views/recurrings/index.blade.php
resources/views/recurrings/index.blade.php
</div>
</div>
<div class="row__column row__column--middle">
- @if ($recurring->due_days)
+ @if ($recurring->status)
<span style="border-radius: 5px; background: #D8F9E8; color: #51B07F; padding: 5px 10px; font-size: 14px; font-weight: 600;"><i class="fas fa-check fa-xs"></i> Active</span>
@else
<span style="border-radius: 5px; background: #FFE7EC; color: #F25C68; padding: 5px 10px; font-size: 14px; font-weight: 600;"><i class="fas fa-times fa-xs"></i> Inactive</span>

MODIFY
resources/views/recurrings/show.blade.php
resources/views/recurrings/show.blade.php
<h2>{{ $recurring->description }}</h2>
<div class="row my-3">
<div class="row__column row__column--compact">
- @if ($recurring->due_days)
+ @if ($recurring->status)
<span style="border-radius: 5px; background: #D8F9E8; color: #51B07F; padding: 5px 10px; font-size: 14px; font-weight: 600;"><i class="fas fa-check fa-xs"></i> Active</span>
@else
<span style="border-radius: 5px; background: #FFE7EC; color: #F25C68; padding: 5px 10px; font-size: 14px; font-weight: 600;"><i class="fas fa-times fa-xs"></i> Inactive</span>

Add status attribute to Recurring model