There's no else counterpart to when() when using multiple conditions (if/elseif/else), but if you think of it, it's just the inverse of the sum of the other conditions. To exactly mirror a PHP if/elseif/else, you need to check the first condition, and then explicitly check the second condition and not the first condition, and to mimic the else condition, its just whichever boolean condition is needed when all else conditions fails.
$query = DB::table('table')
->select('*')
->when($count < 3, function ($q) {
// if count < 3
})
->when($count > 7, function ($q) {
// else if count > 7
})
->when($count =< 7 && $count >= 3, function($q) {
// Else, count between 3 and 7 (inclusive)
});
You can conditionally apply a where clause "manually" by using native PHP if/elseif/else controls and apply a simple where(), which might be more explicit if your conditions become very expressive or complex.
There is however an else condition when you have a simple if/else, as you can provide it another closure. This cannot be used with multiple conditions, as you've originally asked about, but I included it for reference.
$query = DB::table('table')
->select('*')
->when($count < 3, function ($q) {
// if count < 3
}, function($q) {
// Else, count greater or equal to 3
});