Repository navigation
Expand file tree
/
Copy pathLinkPreview.php
More file actions
78 lines (70 loc) · 1.92 KB
/
Copy pathLinkPreview.php
File metadata and controls
78 lines (70 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
namespace App\Models;
use App\Services\Embeds;
use Carbon\CarbonInterface;
use Database\Factories\LinkPreviewFactory;
use Illuminate\Database\Eloquent\Attributes\Visible;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* @property-read string $id
* @property-read string $url
* @property-read string $url_hash
* @property-read string|null $title
* @property-read string|null $description
* @property-read string|null $image_url
* @property-read string|null $site_name
* @property-read CarbonInterface|null $fetched_at
* @property-read CarbonInterface $created_at
* @property-read CarbonInterface $updated_at
*/
#[Visible([
'url',
'title',
'description',
'image_url',
'site_name',
])]
final class LinkPreview extends Model
{
/** @use HasFactory<LinkPreviewFactory> */
use HasFactory;
use HasUuids;
/**
* @return array<string, string>
*/
public function casts(): array
{
return [
'id' => 'string',
'url' => 'string',
'url_hash' => 'string',
'title' => 'string',
'description' => 'string',
'image_url' => 'string',
'site_name' => 'string',
'fetched_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
}
/**
* The commits whose link card it is.
*
* @return HasMany<Commit, $this>
*/
public function commits(): HasMany
{
return $this->hasMany(Commit::class);
}
/**
* @return array<mixed>
*/
public function toArray(): array
{
return [...parent::toArray(), 'is_pending' => $this->fetched_at === null, 'embed' => resolve(Embeds::class)->for($this->url)?->toArray()];
}
}