Pritbor Team
12/13/2024, 1:42 PMproperty_features.number
has an incorrect type. Hint: field inside an array of objects cannot be coerced into an array type as well.
[
'name' => 'property_features', // Nested object for features
'type' => 'object[]',
'optional' => true,
'facet' => true,
'fields' => [
[
'name' => 'feature_name',
'type' => 'string',
'facet' => true,
'optional' => true,
],
[
'name' => 'number',
'type' => 'int64', // Adjust type if number is not integer
'facet' => false,
'optional' => true,
],
[
'name' => 'max_number',
'type' => 'int64', // Adjust type if max_number is not integer
'facet' => false,
'optional' => true,
],
[
'name' => 'feature_options', // Assuming JSON string for selected options
'type' => 'string[]',
'optional' => true,
'facet' => true,
],
],
],
Fanis Tharropoulos
12/13/2024, 2:27 PMPritbor Team
12/13/2024, 6:55 PMpublic function toSearchableArray()
{
$features = [];
foreach ($this->propertyPropertyTypeFeatures as $propertyFeature) {
if($propertyFeature){
$features[] = [
'feature_name' => (string)$propertyFeature->propertyTypeFeature->name, // Keep for efficiency
'number' => (int)($propertyFeature->number ?? 0),
'max_number' => (int)($propertyFeature->max_number ?? 0),
'feature_options' => $propertyFeature->selected_feature_types,
];
}
else{
$features = null;
}
}
$amenities = $this->propertyAmenities->pluck('name')->toArray();
$updatedAt = $this->updated_at->timestamp;
return array_merge($this->toArray(), [
'id' => (string) $this->id,
'title' => $this->title,
'property_type_name' => $this->propertyType->name,
'property_features' => $features,
'property_amenities' => $amenities,
'updated_at' => $updatedAt,
]);
}
And i have below in scout.php for Property model
[
'name' => 'property_features', // Nested object for features
'type' => 'object[]',
'optional' => true,
'facet' => true,
'fields' => [
[
'name' => 'feature_name',
'type' => 'string',
'facet' => true,
'optional' => true,
],
[
'name' => 'number',
'type' => 'int64', // Adjust type if number is not integer
'facet' => false,
'optional' => true,
],
[
'name' => 'max_number',
'type' => 'int64', // Adjust type if max_number is not integer
'facet' => false,
'optional' => true,
],
[
'name' => 'feature_options', // Assuming JSON string for selected options
'type' => 'string[]',
'optional' => true,
'facet' => true,
],
],
],
Pritbor Team
12/13/2024, 7:01 PM