0

I have a live application for my app,(say at mysite.com). As part of my customer on boarding, I have a demo site at (demo.mysite.com), this is where I show potential customer what the app can do, etc. (Different databases and url). In order manage my system, i created also an admin panel on my live site.

Is it possible for me to control the demo site from my live site admin panel. I need to perform activities like,

  1. After a user signs up on live site for a demo account, I create a demo customer via the admin panel after reviewing the request. Which means I need to access the demo site via controller to make a new "demo" customer model, is this possible? I know that I can make multiple mysql connections from live. But how can I perform Eloquent model operation from my live site?

  2. Should I set up a different set up for my demo site.? Is this over complicated? I can set-up a demo accounts for my potential customers on my live site as well. I chose this set up thinking that it's safer in terms protecting data on my production site.

eleven0
  • 263
  • 6
  • 13
  • Personally I would run the demo in a separate application, this ofc can be on the same server. Just for the sake of protecting your live application from leaking. Also it would be easier to reset uploads and database tables. Example would be making a sub domain like demo.mysite.com – Thomas Van der Veen Jul 09 '19 at 17:01
  • Why not just put them on the production site, in a "free trial" sort of mode, and give them the option to clear out the test data once they convert to paid? – ceejayoz Jul 09 '19 at 17:06
  • @ThomasVanderVeen As I mentioned in my original question, I do that already. How would I manipulate data on my demo laravel app from my production app? (Question 1). – eleven0 Jul 09 '19 at 17:58
  • @ceejayoz I think Tomas Van der Veen answered your question. Since I am also a beginner, I am trying to avoid messing with live application as much as possible. – eleven0 Jul 09 '19 at 18:00
  • Sorry must have missed that. Like Shizzen83 mentions in his answer, you can switch database connections dynamically by using `on()` ([source](https://laravel.com/api/5.8/Illuminate/Database/Eloquent/Model.html#method_on)). However you marked that as incorrect, which I find difficult to understand. What would you say about adding the connection of the demo version to the live version? That way you can connect to the demo from the live. – Thomas Van der Veen Jul 10 '19 at 01:02

1 Answers1

0
$demoUser = App\User::on('demo')->create([
   //your attributes
]);

Here is an example how you can achieve an Eloquent operation on another connection. The on method returns a Illuminate\Database\Eloquent\Builder instance, btw you can go on and do whatever you want.

Shizzen83
  • 3,325
  • 3
  • 12
  • 32
  • instance of `Illuminate\Database\Eloquent\Builder` user model in my Demo app from my admin panel of live app? I couldn't find any documentation on laravel site. Do you have it? – eleven0 Jul 09 '19 at 18:15
  • On https://laravel.com/docs/5.8/eloquent, you can see that `$connection` property allows you to specify a connection depending on the model. The `on` method of a model does exactly the same thing, dynamically though because you use many databases on the same model. You can look for this method directly in `Illuminate\Database\Eloquent\Model`, its header says `@return \Illuminate\Database\Eloquent\Builder` – Shizzen83 Jul 09 '19 at 18:29
  • Again ---- this does not help as the model is still within "live" version.... This is only good for if one application is using multiple databases, which in my case, I dont. I have two databases and two applications. – eleven0 Jul 09 '19 at 19:30
  • Even if you have many apps, as long as you work on the same model implementation, you can post data on "live" side to "demo" DB and retrieve them on the "demo" side from "demo" DB, btw my example still works. – Shizzen83 Jul 09 '19 at 19:53