| 229 | | $packageData = $request->validate([ |
| 230 | | 'package_name' => 'required|string|max:255', |
| 231 | | 'price' => 'required|numeric', |
| 232 | | 'start_date' => 'required|date', |
| 233 | | 'end_date' => 'required|date|after_or_equal:start_date', |
| 234 | | 'id_destination' => 'required|integer|exists:destination,id_destination' |
| 235 | | ]); |
| 236 | | |
| 237 | | $package = TravelPackage::create($packageData); |
| | 224 | $package = TravelPackage::create([ |
| | 225 | 'package_name' => $request->package_name, |
| | 226 | 'price' => $request->price, |
| | 227 | 'start_date' => $request->start_date, |
| | 228 | 'end_date' => $request->end_date, |
| | 229 | 'id_destination' => $request->id_destination |
| | 230 | ]); |
| 240 | | $validatedActivity = validator($activityData, [ |
| 241 | | 'activity_name' => 'required|string|max:255', |
| 242 | | 'information' => 'nullable|string|max:255', |
| 243 | | 'category' => 'required|string|max:255', |
| 244 | | 'amount' => 'nullable|numeric', |
| 245 | | 'id_destination' => 'required|integer|exists:destination,id_destination' |
| 246 | | ])->validate(); |
| 247 | | |
| 248 | | $activity = TravelActivity::create($validatedActivity); |
| | 233 | $activity = TravelActivity::create($activityData); |
| 264 | | Reservation::create([ |
| 265 | | 'id_user' => auth()->id(), |
| 266 | | 'id_package' => $package->id_package, |
| 267 | | 'time_point' => now() |
| 268 | | ]); |
| 269 | | }); |
| 270 | | }}} |
| 271 | | |
| 272 | | 4. Пакет со повеќе активности |
| 273 | | {{{ |
| 274 | | DB::transaction(function () use ($request) { |
| 275 | | $package = TravelPackage::create([...]); |
| 276 | | foreach ($request->activities as $activity) { |
| 277 | | $act = TravelActivity::create([...]); |
| 278 | | DB::table('activity_reservation')->insert([ |
| 279 | | 'id_user' => auth()->id(), |
| 280 | | 'id_activity' => $act->id_activity, |
| 281 | | 'reservation_date' => now() |
| 282 | | ]); |
| 283 | | DB::table('activity')->where('id_activity', $act->id_activity)->decrement('amount', 1); |
| 284 | | } |