1
|
|
|
<?php namespace Arcanesoft\Blog\Models; |
2
|
|
|
|
3
|
|
|
use Arcanesoft\Blog\Bases\Model; |
4
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Category |
8
|
|
|
* |
9
|
|
|
* @package Arcanesoft\Blog\Models |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
* |
12
|
|
|
* @property int id |
13
|
|
|
* @property string name |
14
|
|
|
* @property string slug |
15
|
|
|
* @property \Carbon\Carbon created_at |
16
|
|
|
* @property \Carbon\Carbon updated_at |
17
|
|
|
* @property \Carbon\Carbon deleted_at |
18
|
|
|
*/ |
19
|
|
|
class Category extends Model |
20
|
|
|
{ |
21
|
|
|
/* ------------------------------------------------------------------------------------------------ |
22
|
|
|
| Traits |
23
|
|
|
| ------------------------------------------------------------------------------------------------ |
24
|
|
|
*/ |
25
|
|
|
use SoftDeletes; |
26
|
|
|
|
27
|
|
|
/* ------------------------------------------------------------------------------------------------ |
28
|
|
|
| Properties |
29
|
|
|
| ------------------------------------------------------------------------------------------------ |
30
|
|
|
*/ |
31
|
|
|
/** |
32
|
|
|
* The database table used by the model |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $table = 'categories'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The attributes that are mass assignable |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
protected $fillable = ['name']; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Set or unset the timestamps for the model |
47
|
|
|
* |
48
|
|
|
* @var bool |
49
|
|
|
*/ |
50
|
|
|
public $timestamps = true; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The attributes that should be mutated to dates. |
54
|
|
|
* |
55
|
|
|
* @var array |
56
|
|
|
*/ |
57
|
|
|
protected $dates = ['deleted_at']; |
58
|
|
|
|
59
|
|
|
/* ------------------------------------------------------------------------------------------------ |
60
|
|
|
| Relationships |
61
|
|
|
| ------------------------------------------------------------------------------------------------ |
62
|
|
|
*/ |
63
|
|
|
/** |
64
|
|
|
* Relationship with posts. |
65
|
|
|
* |
66
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
67
|
|
|
*/ |
68
|
|
|
public function posts() |
69
|
|
|
{ |
70
|
|
|
return $this->hasMany(Post::class); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/* ------------------------------------------------------------------------------------------------ |
74
|
|
|
| Getters & Setters |
75
|
|
|
| ------------------------------------------------------------------------------------------------ |
76
|
|
|
*/ |
77
|
|
|
/** |
78
|
|
|
* Set the name attribute. |
79
|
|
|
* |
80
|
|
|
* @param string $name |
81
|
|
|
*/ |
82
|
|
|
public function setNameAttribute($name) |
83
|
|
|
{ |
84
|
|
|
$this->attributes['name'] = $name; |
85
|
|
|
$this->attributes['slug'] = str_slug($name); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|