'
'; }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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners