src/Traits/Friendly.php
public function getCurrentFriendsAttribute()
    {
        return $this->friends->filter(function ($item) {
            $now = new \Carbon\Carbon;

            if(!$item->pivot->approved_at)
            {
                return false;
            }

            switch (true) {
                // no dates set
                case !$item->pivot->end && !$item->pivot->start:

                    // start is set but is in the future
                case !$item->pivot->end && $item->pivot->start && $item->pivot->start < $now:

                    // end is set but is in the past
                case !$item->pivot->start && $item->pivot->end && $item->pivot->end > $now:

                    // both start and end are set, but we are currently between those dates
                case $item->pivot->start && $item->pivot->start < $now && $item->pivot->end && $item->pivot->end > $now:

                    return true;
                    break;
            }

            // any other scenario fails
            return false;
        });
    }
public function getCurrentFriendsAttribute()
    {
        return $this->friends->filter(function ($item) {
            $now = new \Carbon\Carbon;

            if(!$item->pivot->approved_at)
            {
                return false;
            }

            switch (true) {
                // no dates set
                case !$item->pivot->end && !$item->pivot->start:

                    // start is set but is in the future
                case !$item->pivot->end && $item->pivot->start && $item->pivot->start < $now:

                    // end is set but is in the past
                case !$item->pivot->start && $item->pivot->end && $item->pivot->end > $now:

                    // both start and end are set, but we are currently between those dates
                case $item->pivot->start && $item->pivot->start < $now && $item->pivot->end && $item->pivot->end > $now:

                    return true;
                    break;
            }

            // any other scenario fails
            return false;
        });
    }
public function getCurrentFriendsAttribute ( ) { return $ this -> friends -> filter ( function ( $ item ) { $ now = new \ Carbon \ Carbon ; if ( ! $ item -> pivot -> approved_at ) { return false ; } switch ( true ) { // no dates set case ! $ item -> pivot -> end && ! $ item -> pivot -> start : // start is set but is in the future case ! $ item -> pivot -> end && $ item -> pivot -> start && $ item -> pivot -> start < $ now : // end is set but is in the past case ! $ item -> pivot -> start && $ item -> pivot -> end && $ item -> pivot -> end > $ now : // both start and end are set, but we are currently between those dates case $ item -> pivot -> start && $ item -> pivot -> start < $ now && $ item -> pivot -> end && $ item -> pivot -> end > $ now : return true ; break ; } // any other scenario fails return false ; } ) ; }
Filters the primary connections by ones that are currently active.

@return mixed
Filters the primary connections by ones that are currently active .