tenantId(); $spaceId = intval($request->spaceId); $tableId = intval($request->table_id); $space = Space::where('restaurant_id', $tenantId) ->where('id', $spaceId) ->first(); if (!$space) { return $this->response(['success' => false, 'error' => 'Space not found']); } $table = Table::where('restaurant_id', $tenantId) ->where('id', $tableId) ->first(); if (!$table) { return $this->response(['success' => false, 'error' => 'Table not found']); } // Verify same area if ($table->area_id != $space->area_id) { return $this->response(['success' => false, 'error' => 'Table and space must belong to the same area']); } $table->space_id = $spaceId; $table->save(); return $this->response([ 'success' => true, 'space' => $space->fresh()->toArray() ]); } public function removeTable(Request $request) { $tenantId = $request->tenantId(); $spaceId = intval($request->spaceId); $tableId = intval($request->table_id); $table = Table::where('restaurant_id', $tenantId) ->where('id', $tableId) ->where('space_id', $spaceId) ->first(); if (!$table) { return $this->response(['success' => false, 'error' => 'Table not found in this space']); } $table->space_id = null; $table->save(); $space = Space::where('id', $spaceId)->first(); return $this->response([ 'success' => true, 'space' => $space ? $space->fresh()->toArray() : null ]); } }