1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CSlant\Blog\Api\Http\Resources\MetaBox; |
4
|
|
|
|
5
|
|
|
use CSlant\Blog\Core\Facades\Base\Media\RvMedia; |
6
|
|
|
use CSlant\Blog\Core\Models\MetaBox; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Illuminate\Http\Resources\Json\JsonResource; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @mixin MetaBox |
12
|
|
|
*/ |
13
|
|
|
class MetaBoxCustomResource extends JsonResource |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param Request $request |
17
|
|
|
* |
18
|
|
|
* @return array<string, mixed> |
19
|
|
|
*/ |
20
|
|
|
public function toArray(Request $request): array |
21
|
|
|
{ |
22
|
|
|
/** @var MetaBox $this */ |
23
|
|
|
|
24
|
|
|
$metaValueCustom = is_array($this->meta_value) && count($this->meta_value) == 1 |
25
|
|
|
? $this->meta_value[0] |
26
|
|
|
: $this->meta_value; |
27
|
|
|
$reference = $this->reference; |
28
|
|
|
|
29
|
|
|
if (is_array($metaValueCustom)) { |
30
|
|
|
$metaValueCustom['seo_title'] = $metaValueCustom['seo_title'] |
31
|
|
|
?? (property_exists($reference, 'name') ? substr($reference->name, 0, 65) : null); |
32
|
|
|
$metaValueCustom['seo_description'] = $metaValueCustom['seo_description'] |
33
|
|
|
?? (property_exists($reference, 'description') ? substr($reference->description, 0, 300) : null); |
34
|
|
|
$metaValueCustom['seo_image'] = !empty($metaValueCustom['seo_image']) ? (RvMedia::getImageUrl($metaValueCustom['seo_image'], '', false, RvMedia::getDefaultImage()) ?? '') : null; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return [ |
38
|
|
|
'meta_key' => $this->meta_key, |
39
|
|
|
'meta_value' => $this->meta_value, |
40
|
|
|
'meta_value_custom' => $metaValueCustom, |
41
|
|
|
//'reference_id' => $this->reference_id, |
42
|
|
|
//'reference_type' => $this->reference_type, |
43
|
|
|
]; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|