1 | <?php namespace VojtaSvoboda\Reservations\Models; |
||
17 | class Reservation extends Model |
||
18 | { |
||
19 | use SoftDeleteTrait; |
||
20 | |||
21 | use ValidationTrait; |
||
22 | |||
23 | /** @var string $table The database table used by the model */ |
||
24 | public $table = 'vojtasvoboda_reservations_reservations'; |
||
25 | |||
26 | /** @var array Rules */ |
||
27 | public $rules = [ |
||
28 | 'date' => 'required|date', |
||
29 | 'locale' => 'max:20', |
||
30 | 'email' => 'required|email', |
||
31 | 'name' => 'required|max:300', |
||
32 | 'street' => 'required|max:300', |
||
33 | 'town' => 'max:300', |
||
34 | 'zip' => 'numeric', |
||
35 | 'phone' => 'required|max:300', |
||
36 | 'message' => 'required|max:3000', |
||
37 | ]; |
||
38 | |||
39 | public $fillable = [ |
||
40 | 'status', 'date', 'locale', 'email', 'name', 'lastname', |
||
41 | 'street', 'town', 'zip', 'phone', 'message', |
||
42 | ]; |
||
43 | |||
44 | public $dates = ['created_at', 'updated_at', 'deleted_at']; |
||
45 | |||
46 | public $belongsTo = [ |
||
47 | 'status' => 'VojtaSvoboda\Reservations\Models\Status', |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * Before create reservation. |
||
52 | */ |
||
53 | 8 | public function beforeCreate() |
|
68 | |||
69 | /** |
||
70 | * Scope for getting non cancelled reservations. |
||
71 | * |
||
72 | * @param $query |
||
73 | * |
||
74 | * @return mixed |
||
75 | */ |
||
76 | 7 | public function scopeNotCancelled($query) |
|
84 | |||
85 | /** |
||
86 | * Set machine scope |
||
87 | * |
||
88 | * @param $query |
||
89 | * |
||
90 | * @return mixed |
||
91 | */ |
||
92 | 7 | public function scopeMachine($query) |
|
100 | |||
101 | /** |
||
102 | * Get default reservation status. |
||
103 | * |
||
104 | * @return Status |
||
105 | */ |
||
106 | 7 | public function getDefaultStatus() |
|
112 | |||
113 | 7 | /** |
|
114 | * Generate unique hash for each reservation. |
||
115 | 7 | * |
|
116 | * @return string|null |
||
117 | */ |
||
118 | public function getUniqueHash() |
||
127 | 6 | ||
128 | /** |
||
129 | * Generate unique number for each reservation. With this hash you can reference |
||
130 | * concrete reservation instead of using internal Reservation ID. |
||
131 | * |
||
132 | * @return string|null |
||
133 | */ |
||
134 | public function getUniqueNumber() |
||
152 | } |
||
153 |