|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
7
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class ArticleCategory |
|
11
|
|
|
* |
|
12
|
|
|
* @property string $title |
|
13
|
|
|
* @property string $slug |
|
14
|
|
|
* @property int $status |
|
15
|
|
|
* @property int $editor_id |
|
16
|
|
|
* @property int $creator_id |
|
17
|
|
|
* |
|
18
|
|
|
* @property Account $editor |
|
19
|
|
|
* @property Account $creator |
|
20
|
|
|
* |
|
21
|
|
|
* @property Carbon $deleted_at |
|
22
|
|
|
* @property Carbon $created_at |
|
23
|
|
|
* @property Carbon $updated_at |
|
24
|
|
|
* |
|
25
|
|
|
* @package App |
|
26
|
|
|
*/ |
|
27
|
|
|
class ArticleCategory extends BaseModel |
|
28
|
|
|
{ |
|
29
|
|
|
/* |
|
30
|
|
|
* Laravel Deleting. |
|
31
|
|
|
* @ https://laravel.com/docs/5.5/eloquent#soft-deleting |
|
32
|
|
|
*/ |
|
33
|
|
|
use SoftDeletes; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The table associated with the model. |
|
37
|
|
|
* |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $table = 'article_categories'; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The attributes that are not mass assignable. |
|
44
|
|
|
* |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $guarded = []; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* The table date columns, casted to Carbon. |
|
51
|
|
|
* |
|
52
|
|
|
* @var array |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Attributes to exclude from the Audit. |
|
58
|
|
|
* |
|
59
|
|
|
* @var array |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $auditExclude = []; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
65
|
|
|
*/ |
|
66
|
|
|
public function articles() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->hasMany(Article::class,'category_id','id'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get the creator model of the eloquent model. |
|
73
|
|
|
* |
|
74
|
|
|
* @return Account|\Illuminate\Database\Eloquent\Relations\BelongsTo |
|
75
|
|
|
*/ |
|
76
|
|
|
public function creator() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->belongsTo(Account::class, 'creator_id', 'id'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get the creator model of the eloquent model. |
|
83
|
|
|
* |
|
84
|
|
|
* @return Account|\Illuminate\Database\Eloquent\Relations\BelongsTo |
|
85
|
|
|
*/ |
|
86
|
|
|
public function editor() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->belongsTo(Account::class, 'editor_id', 'id'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Slug the title for url usage. |
|
93
|
|
|
* |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getSlugAttribute() |
|
97
|
|
|
{ |
|
98
|
|
|
return str_slug($this->getAttribute('title')); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* The name of the current model object. |
|
103
|
|
|
* |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
public function name() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->getAttribute('title'); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|