1 | <?php namespace Arcanedev\LaravelSeo\Models; |
||
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 | 22 | public function __construct(array $attributes = []) |
|
75 | |||
76 | /* ----------------------------------------------------------------- |
||
77 | | Relationships |
||
78 | | ----------------------------------------------------------------- |
||
79 | */ |
||
80 | |||
81 | /** |
||
82 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
83 | */ |
||
84 | 4 | public function seoable() |
|
88 | |||
89 | /* ----------------------------------------------------------------- |
||
90 | | Other Methods |
||
91 | | ----------------------------------------------------------------- |
||
92 | */ |
||
93 | |||
94 | /** |
||
95 | * Prepare the attributes. |
||
96 | * |
||
97 | * @param array $attributes |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | 20 | public static function prepareAttributes(array $attributes) |
|
102 | { |
||
103 | return [ |
||
104 | 20 | 'title' => Arr::get($attributes, 'title'), |
|
105 | 20 | 'description' => Arr::get($attributes, 'description'), |
|
106 | 20 | 'keywords' => Arr::get($attributes, 'keywords', []), |
|
107 | 20 | 'extras' => Arr::get($attributes, 'extras', []), |
|
108 | 20 | 'noindex' => Arr::get($attributes, 'noindex', false), |
|
109 | ]; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Add an extra meta. |
||
114 | * |
||
115 | * @param string $key |
||
116 | * @param mixed $value |
||
117 | * |
||
118 | * @return $this |
||
119 | */ |
||
120 | 2 | public function addExtra($key, $value) |
|
121 | { |
||
122 | 2 | return $this->setExtras( |
|
123 | 2 | $this->extras->put($key, $value)->all() |
|
124 | ); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Add extra metas. |
||
129 | * |
||
130 | * @param mixed $extras |
||
131 | * |
||
132 | * @return $this |
||
133 | */ |
||
134 | 2 | public function addExtras($extras) |
|
135 | { |
||
136 | 2 | return $this->setExtras( |
|
137 | 2 | $this->extras->merge($extras)->all() |
|
138 | ); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Set the extras. |
||
143 | * |
||
144 | * @param mixed $extras |
||
145 | * |
||
146 | * @return $this |
||
147 | */ |
||
148 | 4 | public function setExtras($extras) |
|
154 | } |
||
155 |