Test Failed
Push — master ( 67d6ff...f8d747 )
by Gianluca
16:33
created

Category   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 24
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A children_rec() 0 3 1
A children() 0 3 1
A parent() 0 3 1
A configuration_fields() 0 2 1
1
<?php
2
3
4
namespace Mongi\Mongicommerce\Models;
5
6
7
use Illuminate\Database\Eloquent\Factories\HasFactory;
8
use Illuminate\Database\Eloquent\Model;
9
10
class Category extends Model
11
{
12
    use HasFactory;
13
14
    // Disable Laravel's mass assignment protection
15
    protected $guarded = [];
16
17
    public function parent()
18
    {
19
        return $this->belongsTo(Category::class, 'parent_id');
20
    }
21
22
    public function children_rec()
23
    {
24
        return $this->hasMany(Category::class, 'parent_id');
25
    }
26
27
    public function children()
28
    {
29
        return $this->children_rec()->with('children');
30
    }
31
32
    public function configuration_fields(){
33
        return $this->hasMany(ConfigurationField::class);
34
    }
35
36
}
37