src/Helper.php
public static function hidrateModel($class, $data)
    {
        if ($data instanceof Model) {
            return $data;
        }

        if (!isset($data['pivot'])) {
            throw new \Exception("The 'pivot' attribute in the {$class} is hidden");
        }

        $model = new $class;
        $primaryKey = $model->getKeyName();

        $model->setAttribute($primaryKey, $data[$primaryKey])->setAttribute('name', $data['name']);
        $model->setRelation(
            'pivot',
            MorphPivot::fromRawAttributes($model, $data['pivot'], 'pivot_table')
        );

        return $model;
    }
public static function hidrateModel($class, $data)
    {
        if ($data instanceof Model) {
            return $data;
        }

        if (!isset($data['pivot'])) {
            throw new \Exception("The 'pivot' attribute in the {$class} is hidden");
        }

        $model = new $class;
        $primaryKey = $model->getKeyName();

        $model->setAttribute($primaryKey, $data[$primaryKey])->setAttribute('name', $data['name']);
        $model->setRelation(
            'pivot',
            MorphPivot::fromRawAttributes($model, $data['pivot'], 'pivot_table')
        );

        return $model;
    }
public static function hidrateModel ( $ class , $ data ) { if ( $ data instanceof Model ) { return $ data ; } if ( ! isset ( $ data [ 'pivot' ] ) ) { throw new \ Exception ( "The 'pivot' attribute in the {$class} is hidden" ) ; } $ model = new $ class ; $ primaryKey = $ model -> getKeyName ( ) ; $ model -> setAttribute ( $ primaryKey , $ data [ $ primaryKey ] ) -> setAttribute ( 'name' , $ data [ 'name' ] ) ; $ model -> setRelation ( 'pivot' , MorphPivot :: fromRawAttributes ( $ model , $ data [ 'pivot' ] , 'pivot_table' ) ) ; return $ model ; }
Creates a model from an array filled with the class data.

@param string $class
@param string|\Illuminate\Database\Eloquent\Model $data
@return \Illuminate\Database\Eloquent\Model
Creates a model from an array filled with the class data .