public function followings($class = __CLASS__)
    {
        $table = config('follow.followable_table');
        $foreignKey = config('follow.users_table_foreign_key', 'user_id');
        $targetTable = (new $class())->getTable();
        $tablePrefixedForeignKey = app('db.connection')->getQueryGrammar()->wrap(\sprintf('pivot_followables.%s', $foreignKey));
        $eachOtherKey = app('db.connection')->getQueryGrammar()->wrap('pivot_each_other');

        return $this->morphedByMany($class, config('follow.morph_prefix'), $table)
                    ->wherePivot('relation', '=', Follow::RELATION_FOLLOW)
                    ->withPivot('followable_type', 'relation', 'created_at')
                    ->addSelect("{$targetTable}.*", DB::raw("(CASE WHEN {$tablePrefixedForeignKey} IS NOT NULL THEN 1 ELSE 0 END) as {$eachOtherKey}"))
                    ->leftJoin("{$table} as pivot_followables", function ($join) use ($table, $class, $foreignKey) {
                        $join->on('pivot_followables.followable_type', '=', DB::raw(\addcslashes("'{$class}'", '\\')))
                            ->on('pivot_followables.followable_id', '=', "{$table}.{$foreignKey}")
                            ->on("pivot_followables.{$foreignKey}", '=', "{$table}.followable_id");
                    });
    }
public function followings($class = __CLASS__)
    {
        $table = config('follow.followable_table');
        $foreignKey = config('follow.users_table_foreign_key', 'user_id');
        $targetTable = (new $class())->getTable();
        $tablePrefixedForeignKey = app('db.connection')->getQueryGrammar()->wrap(\sprintf('pivot_followables.%s', $foreignKey));
        $eachOtherKey = app('db.connection')->getQueryGrammar()->wrap('pivot_each_other');

        return $this->morphedByMany($class, config('follow.morph_prefix'), $table)
                    ->wherePivot('relation', '=', Follow::RELATION_FOLLOW)
                    ->withPivot('followable_type', 'relation', 'created_at')
                    ->addSelect("{$targetTable}.*", DB::raw("(CASE WHEN {$tablePrefixedForeignKey} IS NOT NULL THEN 1 ELSE 0 END) as {$eachOtherKey}"))
                    ->leftJoin("{$table} as pivot_followables", function ($join) use ($table, $class, $foreignKey) {
                        $join->on('pivot_followables.followable_type', '=', DB::raw(\addcslashes("'{$class}'", '\\')))
                            ->on('pivot_followables.followable_id', '=', "{$table}.{$foreignKey}")
                            ->on("pivot_followables.{$foreignKey}", '=', "{$table}.followable_id");
                    });
    }
public function followings ( $ class = __CLASS__ ) { $ table = config ( 'follow.followable_table' ) ; $ foreignKey = config ( 'follow.users_table_foreign_key' , 'user_id' ) ; $ targetTable = ( new $ class ( ) ) -> getTable ( ) ; $ tablePrefixedForeignKey = app ( 'db.connection' ) -> getQueryGrammar ( ) -> wrap ( \ sprintf ( 'pivot_followables.%s' , $ foreignKey ) ) ; $ eachOtherKey = app ( 'db.connection' ) -> getQueryGrammar ( ) -> wrap ( 'pivot_each_other' ) ; return $ this -> morphedByMany ( $ class , config ( 'follow.morph_prefix' ) , $ table ) -> wherePivot ( 'relation' , '=' , Follow :: RELATION_FOLLOW ) -> withPivot ( 'followable_type' , 'relation' , 'created_at' ) -> addSelect ( "{$targetTable}.*" , DB :: raw ( "(CASE WHEN {$tablePrefixedForeignKey} IS NOT NULL THEN 1 ELSE 0 END) as {$eachOtherKey}" ) ) -> leftJoin ( "{$table} as pivot_followables" , function ( $ join ) use ( $ table , $ class , $ foreignKey ) { $ join -> on ( 'pivot_followables.followable_type' , '=' , DB :: raw ( \ addcslashes ( "'{$class}'" , '\\' ) ) ) -> on ( 'pivot_followables.followable_id' , '=' , "{$table}.{$foreignKey}" ) -> on ( "pivot_followables.{$foreignKey}" , '=' , "{$table}.followable_id" ) ; } ) ; }
Return item followings.

@param string $class

@return \Illuminate\Database\Eloquent\Relations\BelongsToMany
Return item followings .