Use same database for 2 Laravel Apps - laravel

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.

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.

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

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.

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.

Related

Laravel Debugbar with laravel api routes

I have a Laravel API.
The front end application is completely separate from Laravel.
All Laravel routes are located in routes/api.php
Is there any way to make the Laravel Debugbar work in this case?
https://github.com/barryvdh/laravel-debugbar
barryvdh/laravel-debugbar needs to be installed on your Laravel project (actually all debuggers need to be present within the project to audit every request) and get its files served to the frontend to work (edit repsonses with Middleware/InjectDebugbar.php).
I won't say that it is impossible to get its insights on a separate front, who knows if you are ready to fork the project and communicate with the debug bar APIs.
For a simpler alternatives you can use:
laravel/telescope docs repo
Clockwork browser extension website repo
spatie/laravel-ray(paid) website docs

How to "connect" Laravel project with Craft 3 CMS Website

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?
Let's start of by:
"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.
"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

how to use laravel illuminate in a custom project

I have a static site with a lot of pages. Now I got a new requirement. Client need a Client Area, I am thinking to use laravel Database Eloquent, Session, Form/html, Session and want to use them as alias like use in laravel/lumen. The problem is that I want static pages same as it is with .html extension, is there any solution? I want some packages with aliases to speed up.
I spent a complete day on Configuring Input and Eloquent but I wasn't able to setup to other packages. But I don't know how to set aliases and service providers. Any idea?
Specific:
I need Laravel Some packages
Session,
FileSystem
Mail
Input
Database
Html/Form,
Validation
I don't need others packages and need aliases same as laravel used in (config/app)
yes you can use laravel components outside laravel project please read the article : http://www.richardbagshaw.co.uk/using-illuminate-components/

Getting a laravel script ready for clients

I'm developing a paid application that is based on laravel. I want ideas about how to package the app and how to decrease laravel file size and get rid of all laravel components that is of no use on production/every case, for example: Boris , Predis and maybe Swift email .. What is the proper way to remove them and what other parts of laravel can be removed with no effects?
Scripts could be used in shared hosting or by people with minimum and tech knowledge .. So, it should be easy for them

gradually migrate application from codeigniter to Laravel

I have a quite large application written in Codeigniter 1.7.
It needs some significant enhancements and I have been evaluating Laravel 4 as the PHP framework.
I am trying to find out if anyone has successfully extended an existing Codeigniter application using Laravel so that some screens are Laravel and some are Codeigniter.
I imagine that authentication (currently using Ion Auth) and Session management (using mysql backend) would be two major hurdles to overcome.
If this is an option then I will explore in more detail as the amount of legacy code needing transferring is considerable.
Thanks in advance.
I suppose in your Laravel routes file, create a route for every page you have written in CodeIgniter. Route everything to the URL that CodeIgniter is expecting and as you complete portions in Laravel, change the routes to point to the correct ones Laravel expects as you go.
Before you do anything though, I'd get everything you need for authentication finished in Laravel, turn authentication off in CodeIgniter, and just let Laravel handle that in the routes.

Resources