getCasts() public method

Get the casts array.
public getCasts ( ) : array
return array
Example #1
0
 /**
  * Get the visible model casts for the index.
  *
  * @param  \Illuminate\Database\Eloquent\Model $model
  * @return array
  */
 protected function getVisibleIndexCasts(BaseModel $model)
 {
     if (count($model->getVisible()) > 0) {
         return array_intersect_key($model->getCasts(), array_flip($model->getVisible()));
     }
     return array_diff_key($model->getCasts(), array_flip($model->getHidden()));
 }
 /**
  * cast the properties's type from $casts.
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  */
 protected function castPropertiesType($model)
 {
     $casts = $model->getCasts();
     foreach ($casts as $name => $type) {
         switch ($type) {
             case 'boolean':
             case 'bool':
                 $realType = 'boolean';
                 break;
             case 'string':
                 $realType = 'string';
                 break;
             case 'array':
             case 'json':
                 $realType = 'array';
                 break;
             case 'object':
                 $realType = 'object';
                 break;
             case 'int':
             case 'integer':
             case 'timestamp':
                 $realType = 'integer';
                 break;
             case 'real':
             case 'double':
             case 'float':
                 $realType = 'float';
                 break;
             case 'date':
             case 'datetime':
                 $realType = '\\Carbon\\Carbon';
                 break;
             case 'collection':
                 $realType = '\\Illuminate\\Support\\Collection';
                 break;
             default:
                 $realType = 'mixed';
                 break;
         }
         if (!isset($this->properties[$name])) {
             continue;
         } else {
             $this->properties[$name]['type'] = $this->getTypeOverride($realType);
         }
     }
 }
Example #3
0
 /**
  * Delete.
  *
  * @param Model $model
  * @param Request $request
  *
  * @return bool
  */
 public function delete(Model $model, Request $request)
 {
     // Verificar "multassociations" para zerar
     foreach ($model->getCasts() as $key => $type) {
         if ($type == 'multassociations') {
             $model->{$key}()->sync([], true);
         }
     }
     // Excluir
     $model->delete();
     // Retornar ok
     return true;
 }
Example #4
0
 public function getCasts()
 {
     $this->casts = parent::getCasts();
     $this->casts['_id'] = 'string';
     return $this->casts;
 }