public function newFromBuilder($attributes = array(), $connection = null) {
    $typeField = static::$singleTableTypeField;
    $attributes = (array) $attributes;

    $classType = array_key_exists($typeField, $attributes) ? $attributes[$typeField] : null;

    if ($classType !== null) {
      $childTypes = static::getSingleTableTypeMap();
      if (array_key_exists($classType, $childTypes)) {
        $class = $childTypes[$classType];
        $instance = (new $class)->newInstance([], true);
        $instance->setFilteredAttributes($attributes);
        $instance->setConnection($connection ?: $this->getConnectionName());
        $instance->fireModelEvent('retrieved', false);
        return $instance;
      } else {
        // Something has gone very wrong with the Global Scope
        // There is not graceful recovery so complain loudly.
        throw new SingleTableInheritanceException("Cannot construct newFromBuilder for unrecognized $typeField=$classType");
      }
    } else {
      // There are some cases, like Model::pluck('id'), where $attributes does not contain classType
      // In those situations defer to the original implementation.
      return parent::newFromBuilder($attributes, $connection);
    }
  }
public function newFromBuilder($attributes = array(), $connection = null) {
    $typeField = static::$singleTableTypeField;
    $attributes = (array) $attributes;

    $classType = array_key_exists($typeField, $attributes) ? $attributes[$typeField] : null;

    if ($classType !== null) {
      $childTypes = static::getSingleTableTypeMap();
      if (array_key_exists($classType, $childTypes)) {
        $class = $childTypes[$classType];
        $instance = (new $class)->newInstance([], true);
        $instance->setFilteredAttributes($attributes);
        $instance->setConnection($connection ?: $this->getConnectionName());
        $instance->fireModelEvent('retrieved', false);
        return $instance;
      } else {
        // Something has gone very wrong with the Global Scope
        // There is not graceful recovery so complain loudly.
        throw new SingleTableInheritanceException("Cannot construct newFromBuilder for unrecognized $typeField=$classType");
      }
    } else {
      // There are some cases, like Model::pluck('id'), where $attributes does not contain classType
      // In those situations defer to the original implementation.
      return parent::newFromBuilder($attributes, $connection);
    }
  }
public function newFromBuilder ( $ attributes = array ( ) , $ connection = null ) { $ typeField = static :: $ singleTableTypeField ; $ attributes = ( array ) $ attributes ; $ classType = array_key_exists ( $ typeField , $ attributes ) ? $ attributes [ $ typeField ] : null ; if ( $ classType !== null ) { $ childTypes = static :: getSingleTableTypeMap ( ) ; if ( array_key_exists ( $ classType , $ childTypes ) ) { $ class = $ childTypes [ $ classType ] ; $ instance = ( new $ class ) -> newInstance ( [ ] , true ) ; $ instance -> setFilteredAttributes ( $ attributes ) ; $ instance -> setConnection ( $ connection ? : $ this -> getConnectionName ( ) ) ; $ instance -> fireModelEvent ( 'retrieved' , false ) ; return $ instance ; } else { // Something has gone very wrong with the Global Scope // There is not graceful recovery so complain loudly. throw new SingleTableInheritanceException ( "Cannot construct newFromBuilder for unrecognized $typeField=$classType" ) ; } } else { // There are some cases, like Model::pluck('id'), where $attributes does not contain classType // In those situations defer to the original implementation. return parent :: newFromBuilder ( $ attributes , $ connection ) ; } }
Override the Eloquent method to construct a model of the type given by the value of singleTableTypeField
@param array $attributes
Override the Eloquent method to construct a model of the type given by the value of singleTableTypeField