1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IproSync\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute as CastAttribute; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; |
8
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany; |
9
|
|
|
use Illuminate\Database\Eloquent\Relations\HasOne; |
10
|
|
|
use Illuminate\Support\Arr; |
11
|
|
|
|
12
|
|
|
class Property extends Model |
13
|
|
|
{ |
14
|
|
|
use HasTraitsWithCasts, HasPullAt; |
15
|
|
|
|
16
|
|
|
public $incrementing = false; |
17
|
|
|
|
18
|
|
|
protected $guarded = []; |
19
|
|
|
|
20
|
|
|
protected $casts = [ |
21
|
|
|
'location' => 'array', |
22
|
|
|
'property_attributes' => 'array', |
23
|
|
|
'rooms' => 'array', |
24
|
|
|
'distances' => 'array', |
25
|
|
|
'reviews' => 'array', |
26
|
|
|
'assigned_contacts' => 'array', |
27
|
|
|
'images' => 'array', |
28
|
|
|
'rates' => 'array', |
29
|
|
|
'availabilities' => 'array', |
30
|
|
|
'holiday_extras' => 'array', |
31
|
|
|
'discounts' => 'array', |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
public function getTable(): string |
35
|
|
|
{ |
36
|
|
|
return config('iprosoftware-sync.tables.properties'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function owner(): BelongsTo |
40
|
|
|
{ |
41
|
|
|
return $this->belongsTo(Contact::class, 'owner_contact_id', 'id'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function monthsCustomRates(): HasMany |
45
|
|
|
{ |
46
|
|
|
return $this->hasMany(MonthCustomRate::class, 'property_id', 'id'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function blockouts(): HasMany |
50
|
|
|
{ |
51
|
|
|
return $this->hasMany(Blockout::class, 'property_id', 'id'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function bookings(): HasMany |
55
|
|
|
{ |
56
|
|
|
return $this->hasMany(Booking::class, 'property_id', 'id'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function availability(): HasOne |
60
|
|
|
{ |
61
|
|
|
return $this->hasOne(Availability::class, 'property_id', 'id'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function featureImageUrl(): CastAttribute |
65
|
|
|
{ |
66
|
|
|
return CastAttribute::get(function () { |
67
|
|
|
$images = is_string($this->images) ? json_decode($this->images, true) : $this->images; |
|
|
|
|
68
|
|
|
if (is_array($images) && !empty($images)) { |
69
|
|
|
$image = Arr::first($images); |
70
|
|
|
if (is_array($image)) { |
71
|
|
|
return $image['HostUrl'] ?? null; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return null; |
76
|
|
|
}); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.