$request->get('x'), 'y' => $request->get('y')] ) ); } #[Route(path: '/event/{id}/cancel', methods: ['POST'])] public function cancel(Request $request): Response { $event = DB::fetch(Model::class, 'select * from events where id=:id', ['id' => $request->get('id')])[0] ?? null; $village = Village::get($event->villageId); if ($event->type === 'SendUnits') { $payload = json_decode($event->payload, true); if ($payload['type'] === 'SendBack') { $cancelTimeDiff = $event->createdAt->diff(new \DateTime()); $cancelTime = (new \DateTime())->add($cancelTimeDiff); $cancelPayload = array_replace_recursive($payload, [ 'cancel' => [ 'home' => $payload['destination'], 'residence' => $payload['source'], ], ]); DB::query( 'update events set time=:time, payload=:payload where id=:id', ['time' => $cancelTime->format('c'), 'payload' => json_encode($cancelPayload), 'id' => $request->get('id')] ); } } else { DB::query('delete from event where id=:id', ['id' => $request->get('id')]); } return new RedirectResponse( Router::generate( 'village.show', ['x' => $village->x, 'y' => $village->y] ) ); } }