protected function setName($name)
    {
        //detect relation or relation.field
        $relation = null;
        if (preg_match('#^([a-z0-9_-]+)\.([a-z0-9_-]+)$#i', $name, $matches)) {
            $relation = $matches[1];
            $name = $matches[2];
        } elseif (preg_match('#^[a-z0-9_-]+$#i', $name)) {
            $relation = $name;
        }

        if (isset($this->model) &&
            method_exists($this->model, $relation) &&
            is_a(@$this->model->$relation(), 'Illuminate\Database\Eloquent\Relations\Relation')
        ) {

            $this->relation = $this->model->$relation($relation);
            $this->rel_key = $this->relation->getModel()->getKeyName();
            $this->rel_fq_key = $this->relation->getModel()->getQualifiedKeyName();
            $this->rel_name = $relation;
            $this->rel_field = $name;
            $this->name = ($name != $relation) ? $relation . "_" . $name : $name;

            if (is_a(@$this->relation, 'Illuminate\Database\Eloquent\Relations\BelongsTo')){
                $this->db_name = $this->relation->getForeignKey();
            } else {
                $this->db_name = $name;
            }

            if (is_a(@$this->relation, 'Illuminate\Database\Eloquent\Relations\BelongsToMany')){

                if (method_exists($this->relation, 'getQualifiedRelatedPivotKeyName')) {
                    $this->rel_other_key = $this->relation->getQualifiedRelatedPivotKeyName();
                } elseif (method_exists($this->relation, 'getQualifiedRelatedKeyName')) {
                    $this->rel_other_key = $this->relation->getQualifiedRelatedKeyName();
                } else {
                    $this->rel_other_key = $this->relation->getOtherKey();
                }

            }

            return;
        }

        //otherwise replace dots with underscores so field names are html/js friendly
        $this->name = str_replace(array(".", ",", "`"), array("_", "_", "_"), $name);

        if (!isset($this->db_name))
            $this->db_name = $name;
    }
protected function setName($name)
    {
        //detect relation or relation.field
        $relation = null;
        if (preg_match('#^([a-z0-9_-]+)\.([a-z0-9_-]+)$#i', $name, $matches)) {
            $relation = $matches[1];
            $name = $matches[2];
        } elseif (preg_match('#^[a-z0-9_-]+$#i', $name)) {
            $relation = $name;
        }

        if (isset($this->model) &&
            method_exists($this->model, $relation) &&
            is_a(@$this->model->$relation(), 'Illuminate\Database\Eloquent\Relations\Relation')
        ) {

            $this->relation = $this->model->$relation($relation);
            $this->rel_key = $this->relation->getModel()->getKeyName();
            $this->rel_fq_key = $this->relation->getModel()->getQualifiedKeyName();
            $this->rel_name = $relation;
            $this->rel_field = $name;
            $this->name = ($name != $relation) ? $relation . "_" . $name : $name;

            if (is_a(@$this->relation, 'Illuminate\Database\Eloquent\Relations\BelongsTo')){
                $this->db_name = $this->relation->getForeignKey();
            } else {
                $this->db_name = $name;
            }

            if (is_a(@$this->relation, 'Illuminate\Database\Eloquent\Relations\BelongsToMany')){

                if (method_exists($this->relation, 'getQualifiedRelatedPivotKeyName')) {
                    $this->rel_other_key = $this->relation->getQualifiedRelatedPivotKeyName();
                } elseif (method_exists($this->relation, 'getQualifiedRelatedKeyName')) {
                    $this->rel_other_key = $this->relation->getQualifiedRelatedKeyName();
                } else {
                    $this->rel_other_key = $this->relation->getOtherKey();
                }

            }

            return;
        }

        //otherwise replace dots with underscores so field names are html/js friendly
        $this->name = str_replace(array(".", ",", "`"), array("_", "_", "_"), $name);

        if (!isset($this->db_name))
            $this->db_name = $name;
    }
protected function setName ( $ name ) { //detect relation or relation.field $ relation = null ; if ( preg_match ( '#^([a-z0-9_-]+)\.([a-z0-9_-]+)$#i' , $ name , $ matches ) ) { $ relation = $ matches [ 1 ] ; $ name = $ matches [ 2 ] ; } elseif ( preg_match ( '#^[a-z0-9_-]+$#i' , $ name ) ) { $ relation = $ name ; } if ( isset ( $ this -> model ) && method_exists ( $ this -> model , $ relation ) && is_a ( @ $ this -> model -> $ relation ( ) , 'Illuminate\Database\Eloquent\Relations\Relation' ) ) { $ this -> relation = $ this -> model -> $ relation ( $ relation ) ; $ this -> rel_key = $ this -> relation -> getModel ( ) -> getKeyName ( ) ; $ this -> rel_fq_key = $ this -> relation -> getModel ( ) -> getQualifiedKeyName ( ) ; $ this -> rel_name = $ relation ; $ this -> rel_field = $ name ; $ this -> name = ( $ name != $ relation ) ? $ relation . "_" . $ name : $ name ; if ( is_a ( @ $ this -> relation , 'Illuminate\Database\Eloquent\Relations\BelongsTo' ) ) { $ this -> db_name = $ this -> relation -> getForeignKey ( ) ; } else { $ this -> db_name = $ name ; } if ( is_a ( @ $ this -> relation , 'Illuminate\Database\Eloquent\Relations\BelongsToMany' ) ) { if ( method_exists ( $ this -> relation , 'getQualifiedRelatedPivotKeyName' ) ) { $ this -> rel_other_key = $ this -> relation -> getQualifiedRelatedPivotKeyName ( ) ; } elseif ( method_exists ( $ this -> relation , 'getQualifiedRelatedKeyName' ) ) { $ this -> rel_other_key = $ this -> relation -> getQualifiedRelatedKeyName ( ) ; } else { $ this -> rel_other_key = $ this -> relation -> getOtherKey ( ) ; } } return ; } //otherwise replace dots with underscores so field names are html/js friendly $ this -> name = str_replace ( array ( "." , "," , "`" ) , array ( "_" , "_" , "_" ) , $ name ) ; if ( ! isset ( $ this -> db_name ) ) $ this -> db_name = $ name ; }
check for relation notation and split relation-name and fiel-dname
@param $name
check for relation notation and split relation - name and fiel - dname