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 | 8 | ]; |
|
54 | |||
55 | 8 | /** |
|
56 | 8 | * Before create reservation. |
|
57 | */ |
||
58 | 8 | public function beforeCreate() |
|
73 | |||
74 | /** |
||
75 | * Scope for getting non cancelled reservations. |
||
76 | 7 | * |
|
77 | * @param $query |
||
78 | 7 | * |
|
79 | * @return mixed |
||
80 | 7 | */ |
|
81 | 7 | public function scopeNotCancelled($query) |
|
89 | |||
90 | /** |
||
91 | * Set machine scope |
||
92 | 7 | * |
|
93 | * @param $query |
||
94 | 7 | * |
|
95 | 7 | * @return mixed |
|
96 | 7 | */ |
|
97 | public function scopeMachine($query) |
||
105 | |||
106 | 7 | /** |
|
107 | * Get default reservation status. |
||
108 | * |
||
109 | 7 | * @return Status |
|
110 | 7 | */ |
|
111 | public function getDefaultStatus() |
||
117 | |||
118 | /** |
||
119 | * Generate unique hash for each reservation. |
||
120 | * |
||
121 | * @return string|null |
||
122 | */ |
||
123 | 6 | public function getUniqueHash() |
|
132 | |||
133 | /** |
||
134 | * Generate unique number for each reservation. With this hash you can reference |
||
135 | 9 | * concrete reservation instead of using internal Reservation ID. |
|
136 | * |
||
137 | 9 | * @return string|null |
|
138 | 9 | */ |
|
139 | public function getUniqueNumber() |
||
157 | } |
||
158 |