I have a complex layout that requires me to use PHP, so I'm creating an addon. I want to sort the collection by date, and I have two issues I'm running into.

  1. Looking at the data stored for each item in the collection, I don't see any dates stored. Does Statamic not create a "date" for when an item is added? Is that something you have to handle manually by adding in a field that records the date?

  2. I'm using Statamic\API\Entry to pull the collection. To test things out, I'm trying to sort by title, but that doesn't seem to be working. Here's my code, based on the examples and the Laravel documentation, this looks like it should work, but it's not actually sorting anything.

$projects = Entry::whereCollection('project');
$sortedProjects = $projects->sortBy('title');