Replies: 3 comments 4 replies
-
Not here to help, just struggling with replicator fields as well :) Whats the data type on |
Beta Was this translation helpful? Give feedback.
-
Are you using Statamic headless? |
Beta Was this translation helpful? Give feedback.
-
I solved this by using Antlers:
But this did not solve the Controller issue. I'd still love to understand how the data structure works and how to leverage that in controllers. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an increasingly complex setup. A local gym has programs (collection). Let's say for fun: Men's Squash. Each program has sessions (replicator) that run for a couple of months. Inside each session, there might be days of the week options (replicator) for Mondays and there might be an option for Fridays. Then to make things even harder, some of the options might run for 5 weeks while another runs 6 weeks depending on a bunch of uncontrollable variables like holidays.
So I have a program: Mens Squash
With a session: Spring
And each session has multiple day/time options that run for possibly different amounts of time: i.e. Mondays for 5 weeks at 5pm and Fridays for 6 weeks at 7pm.
Thankfully there are not a ton of programs and each only has a couple sessions, so we aren't talking about a large amount of data.
My goal is to set up a JSON response from a controller action/route so that I can load all these into a FullCalendar.
In the controller, I can easily get the Programs that have a start_date (just added for convenience in the query) greater than today.
$programs = Entry::query() ->where('collection', 'programs') ->where('session_start_date', '>=', date('Y-m-d')) ->get();
Based on playing around with the data returned from the query would have to nest a couple foreach's but that's not the end of the world.
The problem is that if I try to get the nested data output in a simple dd(), it is echoing out the whole collection and not getting me the smaller subset.
Example:
`foreach($programs as $p){
foreach($p->sessions as $s){
dd($s) // this outputs the whole program
}
}`
Is this due to augmentation? How can I work my way down through the replicators?
thanks
Beta Was this translation helpful? Give feedback.
All reactions