PHP code example of paulhenri-l / eloquent-builder-decorator

1. Go to this page and download the library: Download paulhenri-l/eloquent-builder-decorator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

paulhenri-l / eloquent-builder-decorator example snippets


class QueryWithActive extends PaulhenriL\EloquentBuilderDecorator\AbstractBuilderDecorator
{
    public function whereActive()
    {
        return static::decorate(
            $this->queryToDecorate->where('active', true)
        );
    }
}

$usersQuery = User::query();
$usersQuery = new QueryWithActive($query);

// We can now call whereActive() on the query.
$activeUsersCount = $usersQuery->whereActive()->count();

$podcastsQuery = \DB::table('podcasts');

$podcastsQuery = new QueryWithDates($podcastsQuery);
$podcastsQuery = new QueryWithRegion($podcastsQuery);

$podcasts = $podcastsQuery->where('host', 'someone')
    ->happeningToday()
    ->inEurope()
    ->take(10)
    ->get();

public function whereActive()
{
    return static::decorate(
        $this->queryToDecorate->where('active', true)
    );
}

public function whereActive()
{
    return $this->queryToDecorate->where('active', true)
}