<p>I'd make a template called <code>landing</code> that would have various entries/entry types in it where I can add whatever CMS content I want.</p>

<pre><code>https://www.example.com/landing/landing-page-slug
</code></pre>

<p>For a nice content authoring experience, I'd make a custom Element that knows to go out over the wire and fetch the data from the Laravel database via whatever JSON endpoint you've set up in your Laravel app, and a custom Field that is just a simple ElementSelect for my custom Element.</p>

<p>That way in your Craft CMS entry, you could just click a button to browse the various rows in your remote Laravel db (presenting the information in a nice UI that'd look exactly like you're selecting another Craft entry).</p>

<p>Then on the templating side of things, it'd work like anything else does in Craft. Through the custom Element, you'd have access to all of the data from your remote Laravel db table, e.g.:</p>

<pre><code>{{ entry.laravelData.someField }}
</code></pre>

<p>Bonus points would be awarded for a nice caching layer to keep things performant.</p>

CC BY-SA 4.0
2018-07-14T08:10:57.900Z
Just an additional information to this great answer: if you don't want to store custom elements or additional records you could as well create a custom field that fetches the data in the `normalizeValue` function. Your field could contain a simple json object that contains information about how to speak to your JSON endpoint and when you populate it, fetch this data directly instead of creating an element. Or if lazy loading is important you populate the field with some kind of "query" like relation fields do to get it on demand
Robin Schambach
CC BY-SA 4.0
2018-07-14T09:45:09.520Z
Thank you andrew! I think this is exactly what I am searching for. I understand the "concept" but absolutely have no idea how to start this in Craft. I develop a module with a Custom Element (https://docs.craftcms.com/v3/extend/element-types.html#getting-started)? Where would I add the functionality to fetch die JSON-data and parse it into Craft database? So in this case I would have to sync the both databases?
rakete
CC BY-SA 4.0
2018-07-14T09:49:40.820Z
What about this approach? https://craftcms.stackexchange.com/questions/9600/best-solution-for-get-json-results-from-third-party-api
rakete
CC BY-SA 4.0
2018-07-14T09:51:46.510Z
https://verbb.io/craft-plugins/feed-me/features
rakete
CC BY-SA 4.0
2018-07-14T10:00:03.953Z
You don't need to sync your database. You can fetch all necessary properties in your elements `get` functions. For example when you do `element->getContent()` you check if `_content` is null and if so access your JSON endpoint. Craft is not so strict like other CMS you have the freedom to do whatever you like with many build in functions, it's totally flexible
Robin Schambach
CC BY-SA 4.0
2018-07-14T04:14:58.727Z
2018-07-14T04:14:58.727Z
andrew.welch
<p>I've developed an app which fetches data from an API based on <strong>Laravel 5.5</strong>. The marketing landingpage of the app is based on Craft CMS Version 3. The marketing website and the API and the databases of both systems are running on the same server.</p>

<p>I want to generate landingpages for each row of table X of the Laravel database.</p>

<p><strong>www.website.com/awesome-landingpage-about-{slug}</strong></p>

<p>What is the best approach to realize this? </p>

<ul>
<li>I don't want to fetch the data directly from Laravel's database</li>
<li>I don't want to synchronize the Craft CMS database with the Laravel (add/remove the rows from the laravel's database as entries to Craft)</li>
<li>It would be awesome to be able to have an entry-type "Landingpage" where we can optionally create a landingpage, referencing to an ID of the laravel table and add additional content for the landingpages. </li>
</ul>

<p><strong>Would be a JSON-API from Laravel to Craft CMS Plugin a good performant idea?</strong></p>

<p><strong>One option would be to use a Dynamic Route and just fetch the data from 127.0.0.1 (because same server) from the template file? Or is there a smarter way in Craft CMS?</strong></p>

<p><a href="https://i.sstatic.net/duV0o.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/duV0o.png" alt="enter image description here"></a></p>

<plugin-development><craft3><modules>
How to develop plugin/module to build landingpage upon fetched JSON-data
# How to develop plugin/module to build landingpage upon fetched JSON-data

(Asked by: username_0 on 2018-07-13)

I've developed an app which fetches data from an API based on **Laravel 5.5**. The marketing landingpage of the app is based on Craft CMS Version 3. The marketing website and the API and the databases of both systems are running on the same server.

I want to generate landingpages for each row of table X of the Laravel database.

**www.website.com/awesome-landingpage-about-{slug}**

What is the best approach to realize this?

* I don't want to fetch the data directly from Laravel's database
* I don't want to synchronize the Craft CMS database with the Laravel (add/remove the rows from the laravel's database as entries to Craft)
* It would be awesome to be able to have an entry-type "Landingpage" where we can optionally create a landingpage, referencing to an ID of the laravel table and add additional content for the landingpages.

**Would be a JSON-API from Laravel to Craft CMS Plugin a good performant idea?**

**One option would be to use a Dynamic Route and just fetch the data from 127.0.0.1 (because same server) from the template file? Or is there a smarter way in Craft CMS?**

[![enter image description here](https://i.sstatic.net/duV0o.png)](https://i.sstatic.net/duV0o.png)

**Tags:** plugin-development, craft3, modules

---

## 1 answers

### Answer by username_1 on 2018-07-14. Score: 4

I'd make a template called landing that would have various entries/entry types in it where I can add whatever CMS content I want.
https://www.example.com/landing/landing-page-slug

For a nice content authoring experience, I'd make a custom Element that knows to go out over the wire and fetch the data from the Laravel database via whatever JSON endpoint you've set up in your Laravel app, and a custom Field that is just a simple ElementSelect for my custom Element.
That way in your Craft CMS entry, you could just click a button to browse the various rows in your remote Laravel db (presenting the information in a nice UI that'd look exactly like you're selecting another Craft entry).
Then on the templating side of things, it'd work like anything else does in Craft. Through the custom Element, you'd have access to all of the data from your remote Laravel db table, e.g.:
{{ entry.laravelData.someField }}

Bonus points would be awarded for a nice caching layer to keep things performant.

> **Comments:**
> **username_2**: Just an additional information to this great answer: if you don't want to store custom elements or additional records you could as well create a custom field that fetches the data in the `normalizeValue` function. Your field could contain a simple json object that contains information about how to speak to your JSON endpoint and when you populate it, fetch this data directly instead of creating an element. Or if lazy loading is important you populate the field with some kind of "query" like relation fields do to get it on demand  
> **username_0**: Thank you andrew! I think this is exactly what I am searching for. I understand the "concept" but absolutely have no idea how to start this in Craft. I develop a module with a Custom Element (https://docs.craftcms.com/v3/extend/element-types.html#getting-started)? Where would I add the functionality to fetch die JSON-data and parse it into Craft database? So in this case I would have to sync the both databases?  
> **username_0**: What about this approach? https://craftcms.stackexchange.com/questions/9600/best-solution-for-get-json-results-from-third-party-api  
> **username_0**: https://verbb.io/craft-plugins/feed-me/features  
> **username_2**: You don't need to sync your database. You can fetch all necessary properties in your elements `get` functions. For example when you do `element->getContent()` you check if `_content` is null and if so access your JSON endpoint. Craft is not so strict like other CMS you have the freedom to do whatever you like with many build in functions, it's totally flexible  

---

