protected function fillModel($datas)
    {
        $grouped = collect($datas)->groupBy('relation_type');
        foreach($grouped as $key => $groups) {

            // no relation
            if ($key === 'not') {
                foreach($groups as $group) {
                    $this->model->fill($group['datas'])->save();
                }
                continue;
            }

            // hasOne relation
            if ($key === 'hasOne') {
                foreach($groups as $group) {
                    $relation = $group['relation'];
                    if (is_null($this->model->$relation)) {
                        $this->model->$relation()->save(new $group['relation_model']($group['datas']));
                        continue;
                    }
                    $this->model->$relation->fill($group['datas'])->save();
                }
                continue;
            }

            // hasMany relation
            if ($key === 'hasMany') {
                foreach($groups as $group) {
                    $relation = $group['relation'];
                    $relation_models = [];
                    foreach ($group['datas'] as $data) {
                        $relation_models[] = new $group['relation_model']($data);
                    }

                    if (isset($group['is_reset']) && $group['is_reset']) {
                        $this->model->$relation()->delete();
                    }

                    // bu if image banner için eklenmiştir
                    if (isset($group['changeToHasOne']) && $group['changeToHasOne']) {
                        if (is_null($this->model->{$group['changeToHasOne']})) {
                            $this->model->{$group['changeToHasOne']}()->save(new $group['relation_model']($group['datas'][0]));
                            continue;
                        }
                        $this->model->{$group['changeToHasOne']}->fill($group['datas'][0])->save();
                        continue;
                    }
                    $this->model->$relation()->saveMany($relation_models);
                }
                continue;
            }
            return false;
        }
        return true;
    }
protected function fillModel($datas)
    {
        $grouped = collect($datas)->groupBy('relation_type');
        foreach($grouped as $key => $groups) {

            // no relation
            if ($key === 'not') {
                foreach($groups as $group) {
                    $this->model->fill($group['datas'])->save();
                }
                continue;
            }

            // hasOne relation
            if ($key === 'hasOne') {
                foreach($groups as $group) {
                    $relation = $group['relation'];
                    if (is_null($this->model->$relation)) {
                        $this->model->$relation()->save(new $group['relation_model']($group['datas']));
                        continue;
                    }
                    $this->model->$relation->fill($group['datas'])->save();
                }
                continue;
            }

            // hasMany relation
            if ($key === 'hasMany') {
                foreach($groups as $group) {
                    $relation = $group['relation'];
                    $relation_models = [];
                    foreach ($group['datas'] as $data) {
                        $relation_models[] = new $group['relation_model']($data);
                    }

                    if (isset($group['is_reset']) && $group['is_reset']) {
                        $this->model->$relation()->delete();
                    }

                    // bu if image banner için eklenmiştir
                    if (isset($group['changeToHasOne']) && $group['changeToHasOne']) {
                        if (is_null($this->model->{$group['changeToHasOne']})) {
                            $this->model->{$group['changeToHasOne']}()->save(new $group['relation_model']($group['datas'][0]));
                            continue;
                        }
                        $this->model->{$group['changeToHasOne']}->fill($group['datas'][0])->save();
                        continue;
                    }
                    $this->model->$relation()->saveMany($relation_models);
                }
                continue;
            }
            return false;
        }
        return true;
    }
protected function fillModel ( $ datas ) { $ grouped = collect ( $ datas ) -> groupBy ( 'relation_type' ) ; foreach ( $ grouped as $ key => $ groups ) { // no relation if ( $ key === 'not' ) { foreach ( $ groups as $ group ) { $ this -> model -> fill ( $ group [ 'datas' ] ) -> save ( ) ; } continue ; } // hasOne relation if ( $ key === 'hasOne' ) { foreach ( $ groups as $ group ) { $ relation = $ group [ 'relation' ] ; if ( is_null ( $ this -> model -> $ relation ) ) { $ this -> model -> $ relation ( ) -> save ( new $ group [ 'relation_model' ] ( $ group [ 'datas' ] ) ) ; continue ; } $ this -> model -> $ relation -> fill ( $ group [ 'datas' ] ) -> save ( ) ; } continue ; } // hasMany relation if ( $ key === 'hasMany' ) { foreach ( $ groups as $ group ) { $ relation = $ group [ 'relation' ] ; $ relation_models = [ ] ; foreach ( $ group [ 'datas' ] as $ data ) { $ relation_models [ ] = new $ group [ 'relation_model' ] ( $ data ) ; } if ( isset ( $ group [ 'is_reset' ] ) && $ group [ 'is_reset' ] ) { $ this -> model -> $ relation ( ) -> delete ( ) ; } // bu if image banner için eklenmiştir if ( isset ( $ group [ 'changeToHasOne' ] ) && $ group [ 'changeToHasOne' ] ) { if ( is_null ( $ this -> model -> { $ group [ 'changeToHasOne' ] } ) ) { $ this -> model -> { $ group [ 'changeToHasOne' ] } ( ) -> save ( new $ group [ 'relation_model' ] ( $ group [ 'datas' ] [ 0 ] ) ) ; continue ; } $ this -> model -> { $ group [ 'changeToHasOne' ] } -> fill ( $ group [ 'datas' ] [ 0 ] ) -> save ( ) ; continue ; } $ this -> model -> $ relation ( ) -> saveMany ( $ relation_models ) ; } continue ; } return false ; } return true ; }
fill model datas to database

@param array $datas
@return boolean
fill model datas to database