public function assign($data, $whiteList = null)
    {
        if ($whiteList === null) {
            $whiteList = $this->getSafeFields();
        }

        if ($whiteList === null) {
            throw new PreconditionException(['`:model` model do not define accessible fields.', 'model' => static::class]);
        }

        foreach ($whiteList ?: $this->getFields() as $field) {
            if (isset($data[$field])) {
                $value = $data[$field];
                $this->{$field} = is_string($value) ? trim($value) : $value;
            }
        }

        return $this;
    }
public function assign($data, $whiteList = null)
    {
        if ($whiteList === null) {
            $whiteList = $this->getSafeFields();
        }

        if ($whiteList === null) {
            throw new PreconditionException(['`:model` model do not define accessible fields.', 'model' => static::class]);
        }

        foreach ($whiteList ?: $this->getFields() as $field) {
            if (isset($data[$field])) {
                $value = $data[$field];
                $this->{$field} = is_string($value) ? trim($value) : $value;
            }
        }

        return $this;
    }
public function assign ( $ data , $ whiteList = null ) { if ( $ whiteList === null ) { $ whiteList = $ this -> getSafeFields ( ) ; } if ( $ whiteList === null ) { throw new PreconditionException ( [ '`:model` model do not define accessible fields.' , 'model' => static :: class ] ) ; } foreach ( $ whiteList ? : $ this -> getFields ( ) as $ field ) { if ( isset ( $ data [ $ field ] ) ) { $ value = $ data [ $ field ] ; $ this -> { $ field } = is_string ( $ value ) ? trim ( $ value ) : $ value ; } } return $ this ; }
Assigns values to a model from an array

@param array $data
@param array $whiteList =static::sample()

@return static
Assigns values to a model from an array