Fahad Khan
Fahad Khan

Reputation: 375

Use same database for 2 Laravel Apps

I am making a web app on Laravel 5.3 which is frontend app. I am managing data from a Backend App. I have already made models and migrations in the frontend app and not in the backend app. So how should I use same database, models and migrations for both. Please help.

Upvotes: 0

Views: 1206

Answers (4)

davidolrik
davidolrik

Reputation: 452

You can rename the migrations table in your bootstrap/app.php like this:

$app->configure('database');
$app->config->set('database.migrations', 'backend_migrations');

That way you will get two migration tables, one for the frontend, and one for the backend all in the same database.

Upvotes: 0

Jase Moorcroft
Jase Moorcroft

Reputation: 1

There are arguments to support both using an API on the front-end app to access the backend or just recreating the models on each system. I'm supporting multiple sites which access the same data. It soon became apparent that the best way was to create an API on the backend to service them all. Also worked for other shared resources i.e. images.

There is a slight penalty in the load times but is so small it isnt worth noting. It also helped when using other platforms i.e. ioS, android and Ajax.

Upvotes: 0

shalvah
shalvah

Reputation: 895

You didn't mention if your backend app is also using Laravel.

Either way, I think your best approach would be to structure the backend app as an API. Then it would contain the database migrations and models. The back end would be the one to connect directly with the database. The front end would then fetch the data from the back end API and display them. The front end app could then have its own models too (but not database models).

Upvotes: 0

just_chris
just_chris

Reputation: 154

You can just create the models in the backend app and they will still work.

If you are using Artisan:

php artisan make:model ModelName

Migration files can be a little more tricky, I would suggest just managing all of this through your frontend app for consistency and then creating the models you need in the backend app.

Upvotes: 1

Related Questions