'
'; }Step 2. groupBy with Raw ConditionNext, what if you want to group by birth year?
Here’s the visual result for my dummy seeded data:Step 3. groupBy Raw with Boolean ConditionNow we’re getting to the “trick” of the article.
How to group by condition of “born before or after 2001 year”?
Here’s the result view in Blade: @foreach ($results as $result) @endforeach
Adult? Amount
{{ $result->adult == 1 ?
'Yes' : 'No' }}
{{ $result->amount }}
Here’s how it looks visually:You can use such grouping whenever you have clear condition of TRUE/FALSE, like odd/even numbers somewhere, some number is over/under etc.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners