Hello,
I have two tables: regions and places. There's a one-to-many relationship between regions and places. In other words, there are multiple places in a region.
My tables look roughly like this:
regions
=======
id
name
places
=====
id
region_id
name
On the front end, my intention is to do something like this (in the page):
title = "Region and Places"
url = "/region/:slug"
layout = "default"
is_hidden = "0"
[region]
slug = "{{ :slug }}"
==
<h1>{{ region.name }}</h1>
{% for place in region.places %}
<li>
<h3>{{ place.name }}</h3>
</li>
{% else %}
<li class="no-data">No places</li>
{% endfor %}
My attempt (which failed) was to add the following code to my region component:
public function onRun()
{
$this->region = $this->page['region'] = $this->loadRegion();
}
protected function loadRegion()
{
$slug = $this->property('slug');
$region = RegionsModel::with('places')->where('slug', $slug)->first();
return $region;
}
.. and this almost worked, but only the first place name was output. Can anyone help me, or point me to an existing free plug-in that does something similar?
Thanks! Bret
Last updated