1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* App\Models\Reservation. |
10
|
|
|
* |
11
|
|
|
* @property int $id |
12
|
|
|
* @property int $room_id |
13
|
|
|
* @property int $guest_id |
14
|
|
|
* @property string $date_start |
15
|
|
|
* @property string $date_end |
16
|
|
|
* @property int $people |
17
|
|
|
* @property \Illuminate\Support\Carbon $created_at |
18
|
|
|
* @property \Illuminate\Support\Carbon $updated_at |
19
|
|
|
* @property-read \App\Models\Guest $guest |
20
|
|
|
* @property-read \App\Models\Room $room |
21
|
|
|
* |
22
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation getCurrentReservations() |
23
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation getFutureReservations() |
24
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation newModelQuery() |
25
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation newQuery() |
26
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation query() |
27
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation whereCreatedAt($value) |
28
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation whereDateEnd($value) |
29
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation whereDateStart($value) |
30
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation whereGuestId($value) |
31
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation whereId($value) |
32
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation wherePeople($value) |
33
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation whereRoomId($value) |
34
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Reservation whereUpdatedAt($value) |
35
|
|
|
* |
36
|
|
|
* @mixin \Eloquent |
37
|
|
|
*/ |
38
|
|
|
class Reservation extends Model |
39
|
|
|
{ |
40
|
|
|
protected $fillable = [ |
41
|
|
|
'room_id', 'guest_id', 'date_start', 'date_end', 'people', |
42
|
|
|
]; |
43
|
|
|
|
44
|
26 |
|
public function setDateStartAttribute($value) |
45
|
|
|
{ |
46
|
26 |
|
$this->attributes['date_start'] = Carbon::parse($value); |
47
|
26 |
|
} |
48
|
|
|
|
49
|
26 |
|
public function setDateEndAttribute($value) |
50
|
|
|
{ |
51
|
26 |
|
$this->attributes['date_end'] = Carbon::parse($value); |
52
|
26 |
|
} |
53
|
|
|
|
54
|
20 |
|
public function getDateStartAttribute($value) |
55
|
|
|
{ |
56
|
20 |
|
return Carbon::parse($value)->format('d.m.Y'); |
57
|
|
|
} |
58
|
|
|
|
59
|
20 |
|
public function getDateEndAttribute($value) |
60
|
|
|
{ |
61
|
20 |
|
return Carbon::parse($value)->format('d.m.Y'); |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
|
public function scopeGetCurrentReservations($query) |
65
|
|
|
{ |
66
|
2 |
|
return $query->where('date_end', '>=', Carbon::today()) |
67
|
2 |
|
->where('date_start', '<=', Carbon::today()); |
68
|
|
|
} |
69
|
|
|
|
70
|
2 |
|
public function scopeGetFutureReservations($query) |
71
|
|
|
{ |
72
|
2 |
|
return $query->where('date_start', '>', Carbon::today()); |
73
|
|
|
} |
74
|
|
|
|
75
|
24 |
|
public function room() |
76
|
|
|
{ |
77
|
24 |
|
return $this->belongsTo('App\Models\Room'); |
78
|
|
|
} |
79
|
|
|
|
80
|
27 |
|
public function guest() |
81
|
|
|
{ |
82
|
27 |
|
return $this->belongsTo('App\Models\Guest'); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|