public static function with($relations)
    {
        $model = (new static());

        $class = new \ReflectionClass($model);
        $method = $class->getProperty("table");

        $class = explode("\\", $method->class);

        if ($class[count($class)-1] != class_basename($model)) {
            if(self::$_tmptable) {
                $model->setTable(self::$_tmptable);
            }
            $model->bind(config("database.default"), self::$_tmptable);
            return $model->newQuery()->with(
                is_string($relations) ? func_get_args() : $relations
            );
        }else{
            return parent::with($relations);
        }

    }
public static function with($relations)
    {
        $model = (new static());

        $class = new \ReflectionClass($model);
        $method = $class->getProperty("table");

        $class = explode("\\", $method->class);

        if ($class[count($class)-1] != class_basename($model)) {
            if(self::$_tmptable) {
                $model->setTable(self::$_tmptable);
            }
            $model->bind(config("database.default"), self::$_tmptable);
            return $model->newQuery()->with(
                is_string($relations) ? func_get_args() : $relations
            );
        }else{
            return parent::with($relations);
        }

    }
public static function with ( $ relations ) { $ model = ( new static ( ) ) ; $ class = new \ ReflectionClass ( $ model ) ; $ method = $ class -> getProperty ( "table" ) ; $ class = explode ( "\\" , $ method -> class ) ; if ( $ class [ count ( $ class ) - 1 ] != class_basename ( $ model ) ) { if ( self :: $ _tmptable ) { $ model -> setTable ( self :: $ _tmptable ) ; } $ model -> bind ( config ( "database.default" ) , self :: $ _tmptable ) ; return $ model -> newQuery ( ) -> with ( is_string ( $ relations ) ? func_get_args ( ) : $ relations ) ; } else { return parent :: with ( $ relations ) ; } }
Begin querying a model with eager loading.
The default "with" method initializes a model with pre-defined table new.
The table name of a post type is saved in a static variable which is than appended to the model.

@param  array|string $relations
@return \Illuminate\Database\Eloquent\Builder|static
@throws \ReflectionException
Begin querying a model with eager loading . The default with method initializes a model with pre - defined table new . The table name of a post type is saved in a static variable which is than appended to the model .