/**
* Returns a default property mapping for the index based on the casts
* property.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return array
*/
protected function getDefaultIndexMappingProperties(BaseModel $model)
{
$mappings = [];
// Process all date attributes
$dateFormat = $model->getDateFormat();
if ($dateFormat === Carbon::DEFAULT_TO_STRING_FORMAT) {
$dateAttributes = $this->getVisibleIndexDates($model);
foreach ($dateAttributes as $key) {
$mappings[$key] = ['type' => 'date', 'format' => $this->indexMappingDateFormat];
}
}
// Process all casts
$castAttributes = $this->getVisibleIndexCasts($model);
foreach ($castAttributes as $key => $value) {
$indexType = $this->getIndexAttributeType($model, $key);
if (!is_null($indexType)) {
$mappings[$key] = ['type' => $indexType];
if ($indexType === 'date') {
$mappings[$key]['format'] = $this->indexMappingDateFormat;
}
}
}
return $mappings;
}