Illuminate\Database\Eloquent\Model::hasCast PHP Метод

hasCast() публичный Метод

Determine whether an attribute should be cast to a native type.
public hasCast ( string $key, array | string | null $types = null ) : boolean
$key string
$types array | string | null
Результат boolean
    public function hasCast($key, $types = null)
    {
        if (array_key_exists($key, $this->getCasts())) {
            return $types ? in_array($this->getCastType($key), (array) $types, true) : true;
        }
        return false;
    }

Usage Example

Пример #1
0
 /**
  * Get an array with the values of a given column.
  *
  * @param  string  $column
  * @param  string|null  $key
  * @return \Illuminate\Support\Collection
  */
 public function pluck($column, $key = null)
 {
     $results = $this->toBase()->pluck($column, $key);
     // If the model has a mutator for the requested column, we will spin through
     // the results and mutate the values so that the mutated version of these
     // columns are returned as you would expect from these Eloquent models.
     if (!$this->model->hasGetMutator($column) && !$this->model->hasCast($column) && !in_array($column, $this->model->getDates())) {
         return $results;
     }
     return $results->map(function ($value) use($column) {
         return $this->model->newFromBuilder([$column => $value])->{$column};
     });
 }
All Usage Examples Of Illuminate\Database\Eloquent\Model::hasCast
Model