1
|
|
|
<?php namespace Arcanedev\Taxonomies\Models; |
2
|
|
|
|
3
|
|
|
use Arcanedev\LaravelNestedSet\NodeTrait; |
4
|
|
|
use Arcanedev\Taxonomies\Bases\Model; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Category |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\Taxonomies\Models |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
* |
12
|
|
|
* @property int id |
13
|
|
|
* @property string name |
14
|
|
|
* @property string slug |
15
|
|
|
* @property string description |
16
|
|
|
* @property int _lft |
17
|
|
|
* @property int _rgt |
18
|
|
|
* @property int parent_id |
19
|
|
|
* @property \Carbon\Carbon created_at |
20
|
|
|
* @property \Carbon\Carbon updated_at |
21
|
|
|
*/ |
22
|
|
|
class Category extends Model |
23
|
|
|
{ |
24
|
|
|
/* ------------------------------------------------------------------------------------------------ |
25
|
|
|
| Traits |
26
|
|
|
| ------------------------------------------------------------------------------------------------ |
27
|
|
|
*/ |
28
|
|
|
use NodeTrait; |
29
|
|
|
|
30
|
|
|
/* ------------------------------------------------------------------------------------------------ |
31
|
|
|
| Properties |
32
|
|
|
| ------------------------------------------------------------------------------------------------ |
33
|
|
|
*/ |
34
|
|
|
/** |
35
|
|
|
* The attributes that aren't mass assignable. |
36
|
|
|
* |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
protected $fillable = [ |
40
|
|
|
'name', 'slug', 'description', '_lft', '_rgt', 'parent_id', |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Indicates if the model should be timestamped. |
45
|
|
|
* |
46
|
|
|
* @var bool |
47
|
|
|
*/ |
48
|
|
|
public $timestamps = true; |
49
|
|
|
|
50
|
|
|
/* ------------------------------------------------------------------------------------------------ |
51
|
|
|
| Relationships |
52
|
|
|
| ------------------------------------------------------------------------------------------------ |
53
|
|
|
*/ |
54
|
|
|
/** |
55
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo |
56
|
|
|
*/ |
57
|
|
|
public function categorizable() |
58
|
|
|
{ |
59
|
|
|
return $this->morphTo(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $related |
64
|
|
|
* |
65
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany |
66
|
|
|
*/ |
67
|
|
|
public function entries($related) |
68
|
|
|
{ |
69
|
|
|
return $this->morphedByMany( |
70
|
|
|
$related, |
71
|
|
|
config('taxonomies.categories.morph.name', 'categorizable'), |
72
|
|
|
config('taxonomies.categories.morph.table', 'categories_relations') |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/* ------------------------------------------------------------------------------------------------ |
77
|
|
|
| Other Functions |
78
|
|
|
| ------------------------------------------------------------------------------------------------ |
79
|
|
|
*/ |
80
|
9 |
|
public static function tree() |
81
|
|
|
{ |
82
|
9 |
|
return self::get()->toTree()->toArray(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|