I have a table in my database with the fields 'Category' and 'Title'. I have multiple records with the same category but other titles. What I'd like to do is print the category once on my page then show the all the titles with the same category. So Something like this:
Category 1
Title 3(=newest)
Title 2
Title 1(=olddest)
Category 2
Title 1
Category 3
Title 3(=newest)
Title 2
Title 1(=olddest)
Im using the Laravel 4 framework with Eloquent. So I'm getting the result back as an JSON object.
What I have at the moment:
view
@foreach($photos as $photo)
{{$photo->Category}}
@foreach($photo as $category)
{{ $photo->Title }}
@endforeach
@endforeach
Controller
$photos = Photo::orderBy('Date')->get(); // Sort by so that newest photos come first per category
return View::make('myView')->with('photos', $photos);
When looking a bit further I came on to array_add helper but I'm not sure if I can use it and how I really should use it.
Can someone help me achieve the result I need?