hasCast() public method

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
return boolean
コード例 #1
0
ファイル: Builder.php プロジェクト: sopnopriyo/sopnopriyo
 /**
  * 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};
     });
 }
コード例 #2
0
 /**
  * Cast the changes collection to the appropiate type.
  *
  * @param  Collection $changes
  * @param  Model      $adjustment
  * @return mixed
  */
 protected function castChanges(Collection $changes, Model $adjustment)
 {
     $cast = $adjustment->hasCast(config('adjuster.changes_column'));
     switch ($cast) {
         case 'collection':
             return $changes;
         case 'array':
         case 'json':
             return $changes->toArray();
         default:
             return $changes->toJson();
     }
 }