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