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