This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
leorapirap25286
Hi, How do I group records by first letter?
This is my data
A | B | B | B | C | C | D | D |
Avery | Brent | Brad | Beck | Clint | Cary | Doug | Drake |
This is what I want to achieve
A | B | C | D |
Avery |
Brent Brad Beck |
Clint Cary |
Doug Drake |
Code
function onStart()
{
$quotes = Db::table('leorapirap_quotes_authors')
->select(Db::raw('substr(leorapirap_quotes_authors.name,1,1) as alpha,leorapirap_quotes_authors.name as author, leorapirap_quotes_authors.slug'))
->groupBy('name')
->get();
}
$this->page['quotes'] = $quotes;
Markup
{% for quote in this.page.quotes %}
{{ quote.alpha }}
{% endfor %}
Any help is appreciated!
Last updated
1-1 of 1