kordix
1 year ago

Grouping and searching data

Posted 1 year ago by kordix

I want to makes a Jokes application. Basically it's just a typical CRUD with jokes catalogue.

But I have a few slight problems.

First thing is showing all data grouped by given order. It's quite easy - i can just use orderby() on collection. But I need to make modifications in the view - precisely I want to give a header for each group.

So let's say it's like that.

NEW JOKES |vulgar jokes - politics blondes doctors policemen |decent jokes - politics blondes doctors policemen

OLD JOKES |vulgar jokes - politics blondes doctors policemen |decent jokes - politics blondes doctors policemen

With manytomany relationship I can easily define one group given by user, or just group by category. In the view it would like something like that:

@foreach($categories as $category)
    <b>{{$category->title}}</b><br>
    @foreach($category->jokes as $joke)
        {{$joke->title}}
    @endforeach
@endforeach

What I need is category + SUBcategory + SUB-SUBcategory Is there something like groupby() which gives collections array wchich I can use with @foreach in the view?

Please sign in or create an account to participate in this conversation.