|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models\Concerns\Customer; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Storage; |
|
6
|
|
|
use Illuminate\Support\Str; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @property string $telegram_chat_id |
|
10
|
|
|
* @property string $username |
|
11
|
|
|
* @property string $fullname |
|
12
|
|
|
* @property \App\Enum\Gender $gender |
|
13
|
|
|
* @property string $email |
|
14
|
|
|
* @property string $phone_country |
|
15
|
|
|
* @property \Propaganistas\LaravelPhone\PhoneNumber $phone |
|
16
|
|
|
* @property string $whatsapp_phone_country |
|
17
|
|
|
* @property \Propaganistas\LaravelPhone\PhoneNumber $whatsapp_phone |
|
18
|
|
|
* @property string|null $account_number |
|
19
|
|
|
* @property string|null $identitycard_number |
|
20
|
|
|
* @property string|null $identitycard_image |
|
21
|
|
|
* @property float|null $location_latitude |
|
22
|
|
|
* @property float|null $location_longitude |
|
23
|
|
|
* @property-read string|null $google_map_url |
|
24
|
|
|
* @property-read string $whatsapp_phone_url |
|
25
|
|
|
* @property-read string $gravatar_image |
|
26
|
|
|
* @property-read string $telegram_chat_id_censored |
|
27
|
|
|
* |
|
28
|
|
|
* @see \App\Models\Customer |
|
29
|
|
|
*/ |
|
30
|
|
|
trait Attribute |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Return "identitycard_image" attribute value. |
|
34
|
|
|
* |
|
35
|
|
|
* @param mixed $value |
|
36
|
|
|
* @return string|null |
|
37
|
|
|
*/ |
|
38
|
2 |
|
public function getIdentitycardImageAttribute($value): ?string |
|
39
|
|
|
{ |
|
40
|
2 |
|
if (is_null($value)) { |
|
41
|
1 |
|
return null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
return Storage::url(static::IDENTITYCARD_IMAGE_PATH . '/' . $value); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Return "google_map_url" attribute value. |
|
49
|
|
|
* |
|
50
|
|
|
* @return string|null |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function getGoogleMapUrlAttribute(): ?string |
|
53
|
|
|
{ |
|
54
|
1 |
|
if (!is_null($this->location_latitude) && !is_null($this->location_longitude)) { |
|
55
|
1 |
|
return google_map_url($this->location_latitude, $this->location_longitude); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return null; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Return "whatsapp_phone_url" attribute value. |
|
63
|
|
|
* |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getWhatsappPhoneUrlAttribute(): string |
|
67
|
|
|
{ |
|
68
|
|
|
return 'https://wa.me/' . Str::replaceFirst('+', '', $this->whatsapp_phone->formatE164()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Return "gravatar_image" attribute value. |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getGravatarImageAttribute(): string |
|
77
|
|
|
{ |
|
78
|
|
|
return gravatar_image($this->email); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Return "telegram_chat_id_censored" attribute value. |
|
83
|
|
|
* |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getTelegramChatIdCensoredAttribute(): string |
|
87
|
|
|
{ |
|
88
|
|
|
return substr_replace($this->telegram_chat_id, '****', -4); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|