Browse Source

Add bills relation in CareMonth model

Vijayakrishnan Krishnan 5 years ago
parent
commit
4f4a5e9701
1 changed files with 16 additions and 0 deletions
  1. 16 0
      app/Models/CareMonth.php

+ 16 - 0
app/Models/CareMonth.php

@@ -4,6 +4,8 @@ namespace App\Models;
 
 # use Illuminate\Database\Eloquent\Model;
 
+use Illuminate\Support\Collection;
+
 class CareMonth extends Model
 {
     protected $table = 'care_month';
@@ -20,4 +22,18 @@ class CareMonth extends Model
         return $this->hasMany(CareMonthEntry::class, 'care_month_id', 'id');
     }
 
+    public function bills() {
+        return $this->hasMany(Bill::class, 'care_month_id', 'id');
+    }
+
+    public function getBillsOfType($_type) {
+        $bills = $this->bills();
+        $targetBills = new Collection();
+        foreach ($bills as $bill) {
+            if($bill->cm_or_rm === $_type) {
+                $targetBills->add($bill);
+            }
+        }
+        return $targetBills;
+    }
 }