src/BoomCMS/Database/Models/Page.php
public function scopeCurrentVersion(Builder $query)
    {
        $subquery = $this->getCurrentVersionQuery();

        return $query
            ->select('version.*')
            ->addSelect('version.id as version:id')
            ->addSelect('version.created_at as version:created_at')
            ->addSelect('version.created_by as version:created_by')
            ->addSelect('pages.*')
            ->join(DB::raw('('.$subquery->toSql().') as v2'), 'pages.id', '=', 'v2.page_id')
            ->mergeBindings($subquery)
            ->join('page_versions as version', function (JoinClause $join) {
                $join
                    ->on('pages.id', '=', 'version.page_id')
                    ->on('v2.id', '=', 'version.id');
            });
    }
public function scopeCurrentVersion(Builder $query)
    {
        $subquery = $this->getCurrentVersionQuery();

        return $query
            ->select('version.*')
            ->addSelect('version.id as version:id')
            ->addSelect('version.created_at as version:created_at')
            ->addSelect('version.created_by as version:created_by')
            ->addSelect('pages.*')
            ->join(DB::raw('('.$subquery->toSql().') as v2'), 'pages.id', '=', 'v2.page_id')
            ->mergeBindings($subquery)
            ->join('page_versions as version', function (JoinClause $join) {
                $join
                    ->on('pages.id', '=', 'version.page_id')
                    ->on('v2.id', '=', 'version.id');
            });
    }
public function scopeCurrentVersion ( Builder $ query ) { $ subquery = $ this -> getCurrentVersionQuery ( ) ; return $ query -> select ( 'version.*' ) -> addSelect ( 'version.id as version:id' ) -> addSelect ( 'version.created_at as version:created_at' ) -> addSelect ( 'version.created_by as version:created_by' ) -> addSelect ( 'pages.*' ) -> join ( DB :: raw ( '(' . $ subquery -> toSql ( ) . ') as v2' ) , 'pages.id' , '=' , 'v2.page_id' ) -> mergeBindings ( $ subquery ) -> join ( 'page_versions as version' , function ( JoinClause $ join ) { $ join -> on ( 'pages.id' , '=' , 'version.page_id' ) -> on ( 'v2.id' , '=' , 'version.id' ) ; } ) ; }
Scope for getting pages with the current version.

This doesn't work as a global scope as changing the select columns breaks queries which add select columns.

e.g. finding pages by related tags.

@param Builder $query

@return Builder
Scope for getting pages with the current version .