1
|
|
|
<?php namespace jlourenco\blog\Models;
|
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Eloquent\Model;
|
4
|
|
|
use jlourenco\support\Traits\Creation;
|
5
|
|
|
|
6
|
|
|
class BlogPost extends Model
|
7
|
|
|
{
|
8
|
|
|
|
9
|
|
|
/**
|
10
|
|
|
* To allow user actions identity (Created_by, Updated_by, Deleted_by)
|
11
|
|
|
*/
|
12
|
|
|
use Creation;
|
13
|
|
|
|
14
|
|
|
/**
|
15
|
|
|
* {@inheritDoc}
|
16
|
|
|
*/
|
17
|
|
|
protected $table = 'BlogPost';
|
18
|
|
|
|
19
|
|
|
/**
|
20
|
|
|
* The User model name.
|
21
|
|
|
*
|
22
|
|
|
* @var string
|
23
|
|
|
*/
|
24
|
|
|
protected static $usersModel = 'jlourenco\base\Models\BaseUser';
|
25
|
|
|
|
26
|
|
|
/**
|
27
|
|
|
* The Blog category model name.
|
28
|
|
|
*
|
29
|
|
|
* @var string
|
30
|
|
|
*/
|
31
|
|
|
protected static $categoryModel = 'jlourenco\blog\Models\BlogCategory';
|
32
|
|
|
|
33
|
|
|
/**
|
34
|
|
|
* {@inheritDoc}
|
35
|
|
|
*/
|
36
|
|
|
protected $fillable = [
|
37
|
|
|
'title',
|
38
|
|
|
'contents',
|
39
|
|
|
'category',
|
40
|
|
|
'author',
|
41
|
|
|
'likes',
|
42
|
|
|
'shares',
|
43
|
|
|
'views',
|
44
|
|
|
'keywords'
|
45
|
|
|
];
|
46
|
|
|
|
47
|
|
|
/**
|
48
|
|
|
* Returns the user model.
|
49
|
|
|
*
|
50
|
|
|
* @return string
|
51
|
|
|
*/
|
52
|
|
|
public static function getUsersModel()
|
53
|
|
|
{
|
54
|
|
|
return static::$usersModel;
|
55
|
|
|
}
|
56
|
|
|
|
57
|
|
|
/**
|
58
|
|
|
* Sets the user model.
|
59
|
|
|
*
|
60
|
|
|
* @param string $usersModel
|
61
|
|
|
* @return void
|
62
|
|
|
*/
|
63
|
|
|
public static function setUsersModel($usersModel)
|
64
|
|
|
{
|
65
|
|
|
static::$usersModel = $usersModel;
|
66
|
|
|
}
|
67
|
|
|
|
68
|
|
|
/**
|
69
|
|
|
* Returns the category model.
|
70
|
|
|
*
|
71
|
|
|
* @return string
|
72
|
|
|
*/
|
73
|
|
|
public static function getCategoriesModel()
|
74
|
|
|
{
|
75
|
|
|
return static::$categoryModel;
|
76
|
|
|
}
|
77
|
|
|
|
78
|
|
|
/**
|
79
|
|
|
* Sets the categories model.
|
80
|
|
|
*
|
81
|
|
|
* @param string $categoryModel
|
82
|
|
|
* @return void
|
83
|
|
|
*/
|
84
|
|
|
public static function setCategoriesModel($categoryModel)
|
85
|
|
|
{
|
86
|
|
|
static::$categoryModel = $categoryModel;
|
87
|
|
|
}
|
88
|
|
|
|
89
|
|
|
public function getAuthor()
|
90
|
|
|
{
|
91
|
|
|
return $this->belongsTo(static::$usersModel, 'author');
|
92
|
|
|
}
|
93
|
|
|
|
94
|
|
|
public function getCategory()
|
95
|
|
|
{
|
96
|
|
|
return $this->belongsTo(static::$categoryModel, 'category');
|
97
|
|
|
}
|
98
|
|
|
|
99
|
|
|
}
|
100
|
|
|
|