gin0115 / pixie-wpdb

An adaptation of the PIXIE query builder for use exclusively with WordPress and WPDB
MIT License
2 stars 0 forks source link

Introduce WHEN() [V0.2] #36

Open gin0115 opened 2 years ago

gin0115 commented 2 years ago

it woud be nice to introduce WHEN() as per Eloquent.

function when(bool $conditonal, Closure $true, ?Closure $false)
gin0115 commented 2 years ago

Just IF

$builder
->table('foo')
->when($something === 'something', function($builder){
$builder->orderBy('date');
})->get();

IF/ELSE

$builder
->table('foo')
->when(
$sortBy === 'date', 
function($builder){
$builder->orderBy('date');
}),
function($builder){
$builder->orderBy('id');
})
)
->get();