2

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

rakete
  • 2,953
  • 11
  • 54
  • 108

1 Answers1

2

Let's start of by:

  1. "I don't want to fetch the data directly from Laravel's database"

I'm assuming you don't want to write code in CraftCMS to access another project's database. Good. IF you plan on having them do seperate jobs and use Laravel API for fetching data alone, let it handle it's own database.

  1. "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)"

So, this is my question: You want to be able to create landing pages based of Laravel's rows alone or based of Laravel's database row's and CraftCMS's?
It all comes down to how well you want to abstract both frameworks. I would probably tell laravel to accept requests from authenticated user (a CraftCMS User) or from localhosts (from within the machine alone) and I'd create endpoints to add/remove/edit/get data at my disposal. I'd then fetch rows from Laravel and combine with my own (assume I'm the CMS). Even in an intranet network, the request to tell laravel to access the database is longer than to access the database from CraftCMS, so you should expect a dependency between the two projects.

For point 3, you'll have to store information on each database about something. On CraftCMS's to store at least the ID's it's going to request to laravel and laravel will have to get an endpoint where it can insert new stuff, if you're planning on having additional content there.

I'm not entirely sure if I got the idea you're trying to show when you say "add additional content for the landing pages" but I'd try to keep it simple and abstract it's uses, Laravel to store this 'information' that the CMS shouldn't handle in the first place (or you can work out some extra tables and import them to the other database). Impact performance? Depends on the ammount of data you've got

abr
  • 2,071
  • 22
  • 38
  • Hi, thanks for your detailed answer. I don't want to be able to edit the data from Craft CMS. Craft should only be something like a "gateway". It's presenting the website and is fetching the data from Laravel for these landingpages. In addition I could add a Craft's entry with some more information for a specific ID (from Laravel's database) to add for example more text below the information fetched from the Laravel database. I am sure it's confusing, but at the moment, I don't know how to explain it better. – rakete Jul 13 '18 at 22:18
  • So you fetch from laravel by the slug and return, for example, a title, but I dislike the idea of having aditional content on the craftcms's side. If you're fetching content for the landing page on laravel, might aswell fetch everything from one side. I may not be the best person to help you but I'll upvote you as I'm curious at how others may think and get some ideas aswell – abr Jul 13 '18 at 22:34
  • In general I would agree with you about the point with putting all information in one database. But Laravel + MySQL databases focuses on the app functionality. There is a small backend to manage the data in this database. I could add the additional fields there. This would be easier. But I don't want to mix the app data and the marketing content. If I want to add a new slider element or something similar to the landingpage, I would like to do this with my CMS. In Laravel I hope to just have to add one API to offer the data in JSON. But I don't know how to structure such a Craft plugin... – rakete Jul 13 '18 at 23:07