|
1
|
|
|
<?php namespace Arcanedev\LaravelSeo\Models; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\LaravelSeo\Seo; |
|
4
|
|
|
use Illuminate\Support\Arr; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class Meta |
|
8
|
|
|
* |
|
9
|
|
|
* @package Arcanedev\LaravelSeo\Models |
|
10
|
|
|
* @author ARCANEDEV <[email protected]> |
|
11
|
|
|
* |
|
12
|
|
|
* @property int id |
|
13
|
|
|
* @property int seoable_id |
|
14
|
|
|
* @property string seoable_type |
|
15
|
|
|
* @property string title |
|
16
|
|
|
* @property string description |
|
17
|
|
|
* @property \Illuminate\Support\Collection keywords |
|
18
|
|
|
* @property boolean noindex |
|
19
|
|
|
* @property \Illuminate\Support\Collection extras |
|
20
|
|
|
* @property \Carbon\Carbon created_at |
|
21
|
|
|
* @property \Carbon\Carbon updated_at |
|
22
|
|
|
* |
|
23
|
|
|
* @property \Illuminate\Database\Eloquent\Model seoable |
|
24
|
|
|
*/ |
|
25
|
|
|
class Meta extends AbstractModel |
|
26
|
|
|
{ |
|
27
|
|
|
/* ----------------------------------------------------------------- |
|
28
|
|
|
| Traits |
|
29
|
|
|
| ----------------------------------------------------------------- |
|
30
|
|
|
*/ |
|
31
|
|
|
|
|
32
|
|
|
use Presenters\MetaPresenter; |
|
33
|
|
|
|
|
34
|
|
|
/* ----------------------------------------------------------------- |
|
35
|
|
|
| Properties |
|
36
|
|
|
| ----------------------------------------------------------------- |
|
37
|
|
|
*/ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The attributes that are mass assignable. |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $fillable = ['title', 'description', 'keywords', 'noindex', 'extras']; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The attributes that should be casted to native types. |
|
48
|
|
|
* |
|
49
|
|
|
* @var array |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $casts = [ |
|
52
|
|
|
'id' => 'integer', |
|
53
|
|
|
'seoable_id' => 'integer', |
|
54
|
|
|
'keywords' => 'collection', |
|
55
|
|
|
'noindex' => 'boolean', |
|
56
|
|
|
'extras' => 'collection', |
|
57
|
|
|
]; |
|
58
|
|
|
|
|
59
|
|
|
/* ----------------------------------------------------------------- |
|
60
|
|
|
| Constructor |
|
61
|
|
|
| ----------------------------------------------------------------- |
|
62
|
|
|
*/ |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Meta constructor. |
|
66
|
|
|
* |
|
67
|
|
|
* @param array $attributes |
|
68
|
|
|
*/ |
|
69
|
33 |
|
public function __construct(array $attributes = []) |
|
70
|
|
|
{ |
|
71
|
33 |
|
parent::__construct($attributes); |
|
72
|
|
|
|
|
73
|
33 |
|
$this->setTable(Seo::getConfig('metas.table', 'metas')); |
|
74
|
33 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
/* ----------------------------------------------------------------- |
|
77
|
|
|
| Relationships |
|
78
|
|
|
| ----------------------------------------------------------------- |
|
79
|
|
|
*/ |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo |
|
83
|
|
|
*/ |
|
84
|
6 |
|
public function seoable() |
|
85
|
|
|
{ |
|
86
|
6 |
|
return $this->morphTo(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/* ----------------------------------------------------------------- |
|
90
|
|
|
| Other Methods |
|
91
|
|
|
| ----------------------------------------------------------------- |
|
92
|
|
|
*/ |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Prepare the attributes. |
|
96
|
|
|
* |
|
97
|
|
|
* @param array $attributes |
|
98
|
|
|
* |
|
99
|
|
|
* @return array |
|
100
|
|
|
*/ |
|
101
|
30 |
|
public static function prepareAttributes(array $attributes) |
|
102
|
|
|
{ |
|
103
|
|
|
return [ |
|
104
|
30 |
|
'title' => Arr::get($attributes, 'title'), |
|
105
|
30 |
|
'description' => Arr::get($attributes, 'description'), |
|
106
|
30 |
|
'keywords' => Arr::get($attributes, 'keywords', []), |
|
107
|
30 |
|
'extras' => Arr::get($attributes, 'extras', []), |
|
108
|
30 |
|
'noindex' => Arr::get($attributes, 'noindex', false), |
|
109
|
10 |
|
]; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Add an extra meta. |
|
114
|
|
|
* |
|
115
|
|
|
* @param string $key |
|
116
|
|
|
* @param mixed $value |
|
117
|
|
|
* |
|
118
|
|
|
* @return $this |
|
119
|
|
|
*/ |
|
120
|
3 |
|
public function addExtra($key, $value) |
|
121
|
|
|
{ |
|
122
|
3 |
|
return $this->setExtras( |
|
123
|
3 |
|
$this->extras->put($key, $value)->all() |
|
124
|
1 |
|
); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Add extra metas. |
|
129
|
|
|
* |
|
130
|
|
|
* @param mixed $extras |
|
131
|
|
|
* |
|
132
|
|
|
* @return $this |
|
133
|
|
|
*/ |
|
134
|
3 |
|
public function addExtras($extras) |
|
135
|
|
|
{ |
|
136
|
3 |
|
return $this->setExtras( |
|
137
|
3 |
|
$this->extras->merge($extras)->all() |
|
138
|
1 |
|
); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Set the extras. |
|
143
|
|
|
* |
|
144
|
|
|
* @param mixed $extras |
|
145
|
|
|
* |
|
146
|
|
|
* @return $this |
|
147
|
|
|
*/ |
|
148
|
6 |
|
public function setExtras($extras) |
|
149
|
|
|
{ |
|
150
|
6 |
|
$this->extras = collect($extras); |
|
151
|
|
|
|
|
152
|
6 |
|
return $this; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|