getCastType() protected method

Get the type of cast for a model attribute.
protected getCastType ( string $key ) : string
$key string
return string
Example #1
0
 /**
  * Map the type of an Eloquent model attribute to an index attribute type.
  *
  * https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html#mapping-type
  *
  * @param  \Illuminate\Database\Eloquent\Model $model
  * @param  string $key
  * @return string|null
  */
 protected function getIndexAttributeType(BaseModel $model, $key)
 {
     switch ($model->getCastType($key)) {
         case 'int':
         case 'integer':
             return 'integer';
         case 'real':
         case 'float':
             return 'float';
         case 'double':
             return 'double';
         case 'string':
             return 'string';
         case 'bool':
         case 'boolean':
             return 'boolean';
         case 'date':
         case 'datetime':
         case 'timestamp':
             return 'date';
         case 'array':
         case 'collection':
         case 'object':
         case 'json':
             return 'object';
         default:
             break;
     }
     return null;
 }