public function updateOrCreateNew(array $attributes, $key, array $options = []) : Model
    {
        $query = $this->newQuery();

        if (is_array($key)) {
            foreach ($key as $column) {
                $query->where($column, $attributes[$column]);
            }
        } else {
            $query->where($key, $attributes[$key]);
        }

        /** @var Model|Model $row */
        $row = $query->first();

        if ($row !== null) {
            $row->updateExisting(array_replace($row->getAttributes(), $attributes));

            return $row;
        }

        return $this->fillSave($attributes, $options);
    }
public function updateOrCreateNew(array $attributes, $key, array $options = []) : Model
    {
        $query = $this->newQuery();

        if (is_array($key)) {
            foreach ($key as $column) {
                $query->where($column, $attributes[$column]);
            }
        } else {
            $query->where($key, $attributes[$key]);
        }

        /** @var Model|Model $row */
        $row = $query->first();

        if ($row !== null) {
            $row->updateExisting(array_replace($row->getAttributes(), $attributes));

            return $row;
        }

        return $this->fillSave($attributes, $options);
    }
public function updateOrCreateNew ( array $ attributes , $ key , array $ options = [ ] ) : Model { $ query = $ this -> newQuery ( ) ; if ( is_array ( $ key ) ) { foreach ( $ key as $ column ) { $ query -> where ( $ column , $ attributes [ $ column ] ) ; } } else { $ query -> where ( $ key , $ attributes [ $ key ] ) ; } /** @var Model|Model $row */ $ row = $ query -> first ( ) ; if ( $ row !== null ) { $ row -> updateExisting ( array_replace ( $ row -> getAttributes ( ) , $ attributes ) ) ; return $ row ; } return $ this -> fillSave ( $ attributes , $ options ) ; }
Insert or update without dealing with mass assignment

@param array         $attributes
@param string|array  $key
@param array         $options
@return \Laranix\Support\Database\Model
Insert or update without dealing with mass assignment