1
|
|
|
<?php namespace Arcanesoft\Seo\Models; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class Page |
5
|
|
|
* |
6
|
|
|
* @package Arcanesoft\Seo\Models |
7
|
|
|
* @author ARCANEDEV <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @property int id |
10
|
|
|
* @property string name |
11
|
|
|
* @property string content |
12
|
|
|
* @property string locale |
13
|
|
|
* @property \Carbon\Carbon created_at |
14
|
|
|
* @property \Carbon\Carbon updated_at |
15
|
|
|
* |
16
|
|
|
* @property \Illuminate\Database\Eloquent\Collection footers |
17
|
|
|
*/ |
18
|
|
|
class Page extends AbstractModel |
19
|
|
|
{ |
20
|
|
|
/* ----------------------------------------------------------------- |
21
|
|
|
| Traits |
22
|
|
|
| ----------------------------------------------------------------- |
23
|
|
|
*/ |
24
|
|
|
use Presenters\PagePresenter; |
25
|
|
|
|
26
|
|
|
/* ----------------------------------------------------------------- |
27
|
|
|
| Properties |
28
|
|
|
| ----------------------------------------------------------------- |
29
|
|
|
*/ |
30
|
|
|
/** |
31
|
|
|
* The attributes that are mass assignable. |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $fillable = ['name', 'content', 'locale']; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The attributes that should be cast to native types. |
39
|
|
|
* |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
protected $casts = [ |
43
|
|
|
'id' => 'integer', |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
/* ----------------------------------------------------------------- |
47
|
|
|
| Constructor |
48
|
|
|
| ----------------------------------------------------------------- |
49
|
|
|
*/ |
50
|
|
|
/** |
51
|
|
|
* Page constructor. |
52
|
|
|
* |
53
|
|
|
* @param array $attributes |
54
|
|
|
*/ |
55
|
|
|
public function __construct(array $attributes = []) |
56
|
|
|
{ |
57
|
|
|
parent::__construct($attributes); |
58
|
|
|
|
59
|
|
|
$this->setConnection(config('arcanesoft.seo.database.connection')); |
60
|
|
|
$this->setPrefix(config('arcanesoft.seo.database.prefix', 'seo_')); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/* ----------------------------------------------------------------- |
64
|
|
|
| Relationships |
65
|
|
|
| ----------------------------------------------------------------- |
66
|
|
|
*/ |
67
|
|
|
/** |
68
|
|
|
* Footer's relationship. |
69
|
|
|
* |
70
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
71
|
|
|
*/ |
72
|
|
|
public function footers() |
73
|
|
|
{ |
74
|
|
|
return $this->hasMany(Footer::class); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/* ----------------------------------------------------------------- |
78
|
|
|
| Main Methods |
79
|
|
|
| ----------------------------------------------------------------- |
80
|
|
|
*/ |
81
|
|
|
/** |
82
|
|
|
* Create a new page. |
83
|
|
|
* |
84
|
|
|
* @param array $attributes |
85
|
|
|
* |
86
|
|
|
* @return self |
87
|
|
|
*/ |
88
|
|
|
public static function createOne(array $attributes) |
89
|
|
|
{ |
90
|
|
|
$page = new self($attributes); |
91
|
|
|
$page->save(); |
92
|
|
|
|
93
|
|
|
return $page; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Update a page. |
98
|
|
|
* |
99
|
|
|
* @param array $attributes |
100
|
|
|
* |
101
|
|
|
* @return bool |
102
|
|
|
*/ |
103
|
|
|
public function updateOne(array $attributes) |
104
|
|
|
{ |
105
|
|
|
return $this->update($attributes); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/* ----------------------------------------------------------------- |
109
|
|
|
| Check Methods |
110
|
|
|
| ----------------------------------------------------------------- |
111
|
|
|
*/ |
112
|
|
|
/** |
113
|
|
|
* Check if the page is deletable. |
114
|
|
|
* |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
public function isDeletable() |
118
|
|
|
{ |
119
|
|
|
return $this->footers->isEmpty(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/* ----------------------------------------------------------------- |
123
|
|
|
| Other Methods |
124
|
|
|
| ----------------------------------------------------------------- |
125
|
|
|
*/ |
126
|
|
|
/** |
127
|
|
|
* Get the select input data. |
128
|
|
|
* |
129
|
|
|
* @return \Illuminate\Database\Eloquent\Collection |
130
|
|
|
*/ |
131
|
|
|
public static function getSelectInputData() |
132
|
|
|
{ |
133
|
|
|
$pages = Page::all(); // TODO: Cache the data ?? |
134
|
|
|
|
135
|
|
|
return $pages->pluck('name', 'id')->prepend('-- Select a page --', 0); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get the show url (Seoable). |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getShowUrl() |
144
|
|
|
{ |
145
|
|
|
return route('admin::seo.footers.show', $this); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Get the edit url (Seoable). |
150
|
|
|
* |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function getEditUrl() |
154
|
|
|
{ |
155
|
|
|
return route('admin::seo.footers.edit', $this); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|