Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
1 / 2 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| AccountCategory | |
50.00% |
1 / 2 |
|
50.00% |
1 / 2 |
2.50 | |
0.00% |
0 / 1 |
| parent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| children | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use Illuminate\Database\Eloquent\Model; |
| 6 | |
| 7 | /** Income/Expense tree — e.g. Sales, Service under income; Rent, Salary, Utilities under expense. */ |
| 8 | class AccountCategory extends Model |
| 9 | { |
| 10 | protected $fillable = ['name', 'type', 'parent_id', 'is_active']; |
| 11 | |
| 12 | protected $casts = [ |
| 13 | 'is_active' => 'boolean', |
| 14 | ]; |
| 15 | |
| 16 | public function parent() |
| 17 | { |
| 18 | return $this->belongsTo(self::class, 'parent_id'); |
| 19 | } |
| 20 | |
| 21 | public function children() |
| 22 | { |
| 23 | return $this->hasMany(self::class, 'parent_id'); |
| 24 | } |
| 25 | } |