public function scopeForUser(Builder $query, $userId)
    {
        $participantsTable = Models::table('participants');
        $threadsTable = Models::table('threads');

        return $query->join($participantsTable, $this->getQualifiedKeyName(), '=', $participantsTable . '.thread_id')
            ->where($participantsTable . '.user_id', $userId)
            ->where($participantsTable . '.deleted_at', null)
            ->select($threadsTable . '.*');
    }
public function scopeForUser(Builder $query, $userId)
    {
        $participantsTable = Models::table('participants');
        $threadsTable = Models::table('threads');

        return $query->join($participantsTable, $this->getQualifiedKeyName(), '=', $participantsTable . '.thread_id')
            ->where($participantsTable . '.user_id', $userId)
            ->where($participantsTable . '.deleted_at', null)
            ->select($threadsTable . '.*');
    }
public function scopeForUser ( Builder $ query , $ userId ) { $ participantsTable = Models :: table ( 'participants' ) ; $ threadsTable = Models :: table ( 'threads' ) ; return $ query -> join ( $ participantsTable , $ this -> getQualifiedKeyName ( ) , '=' , $ participantsTable . '.thread_id' ) -> where ( $ participantsTable . '.user_id' , $ userId ) -> where ( $ participantsTable . '.deleted_at' , null ) -> select ( $ threadsTable . '.*' ) ; }
Returns threads that the user is associated with.

@param \Illuminate\Database\Eloquent\Builder $query
@param int $userId

@return \Illuminate\Database\Eloquent\Builder
Returns threads that the user is associated with .