1 | <?php namespace VojtaSvoboda\Reservations\Models; |
||
18 | class Reservation extends Model |
||
19 | { |
||
20 | use SoftDeleteTrait; |
||
21 | |||
22 | use ValidationTrait; |
||
23 | |||
24 | /** @var string $table The database table used by the model */ |
||
25 | public $table = 'vojtasvoboda_reservations_reservations'; |
||
26 | |||
27 | /** @var array Rules */ |
||
28 | public $rules = [ |
||
29 | 'date' => 'required|date|reservation', |
||
30 | 'locale' => 'max:20', |
||
31 | 'email' => 'required|email', |
||
32 | 'name' => 'required|max:300', |
||
33 | 'street' => 'required|max:300', |
||
34 | 'town' => 'max:300', |
||
35 | 'zip' => 'numeric', |
||
36 | 'phone' => 'required|max:300', |
||
37 | 'message' => 'required|max:3000', |
||
38 | ]; |
||
39 | |||
40 | public $customMessages = [ |
||
41 | 'reservation' => 'Date :reservation is already booked.', |
||
42 | ]; |
||
43 | |||
44 | public $fillable = [ |
||
45 | 'status', 'date', 'locale', 'email', 'name', 'lastname', |
||
46 | 'street', 'town', 'zip', 'phone', 'message', |
||
47 | ]; |
||
48 | |||
49 | public $dates = ['date', 'created_at', 'updated_at', 'deleted_at']; |
||
50 | |||
51 | public $belongsTo = [ |
||
52 | 'status' => 'VojtaSvoboda\Reservations\Models\Status', |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * Before create reservation. |
||
57 | */ |
||
58 | 11 | public function beforeCreate() |
|
73 | |||
74 | /** |
||
75 | * If reservation is cancelled. |
||
76 | * |
||
77 | * @param string $statusIdent |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | 3 | public function isCancelled($statusIdent = null) |
|
90 | |||
91 | /** |
||
92 | * Scope for getting non cancelled reservations. |
||
93 | * |
||
94 | * @param $query |
||
95 | * |
||
96 | * @return mixed |
||
97 | */ |
||
98 | 11 | public function scopeNotCancelled($query) |
|
106 | |||
107 | /** |
||
108 | * Set machine scope |
||
109 | * |
||
110 | * @param $query |
||
111 | * |
||
112 | * @return mixed |
||
113 | */ |
||
114 | 7 | public function scopeMachine($query) |
|
122 | |||
123 | /** |
||
124 | * Get default reservation status. |
||
125 | * |
||
126 | * @return Status |
||
127 | */ |
||
128 | 5 | public function getDefaultStatus() |
|
134 | |||
135 | /** |
||
136 | * Generate unique hash for each reservation. |
||
137 | * |
||
138 | * @return string|null |
||
139 | */ |
||
140 | 13 | public function getUniqueHash() |
|
149 | |||
150 | /** |
||
151 | * Generate unique number for each reservation. With this hash you can reference |
||
152 | * concrete reservation instead of using internal Reservation ID. |
||
153 | * |
||
154 | * @return string|null |
||
155 | */ |
||
156 | 13 | public function getUniqueNumber() |
|
174 | } |
||
175 |