Automatic Log In/Authentication Laravel from Other Laravel - laravel

I have two Laravel applications that use the same database and, therefore, have the same users and passwords.
Let's say the applications are called A and B.
If a user logs into A, what can I do so that they're automatically logged into B? So if they log into A, then when they go to B, they will not have to type in their login information again.
Both applications are on the same domain, but B is a subdomain and is not part of the same project as A.
Thank you in advance!

When you say Both applications are on the same domain, but B is a subdomain and is not part of the same project as A. can i safely assume that they are two separate installations of Laravel, but they share the same database? I that's the case, you could try this:
Switch the session driver to database in your .env file to "database", for reference you should look at the comments in config/session.php, near the 'driver' => env('SESSION_DRIVER', 'file'), option. Be sure to manage the tables accordingly (see https://laravel.com/docs/5.5/session#driver-prerequisites)
In your .env file, specify this row: SESSION_DOMAIN=.domain.ext (notice the dot near the equal sign).
Alternatively, if even the databases are separate you could try the same config as above using the cookie driver instead fo the database. let me know if this helped.
edit: more a suggestion than an answer, laravel is capable of handling multiple websites/domains natively (example: Route::domain('sub.domain.ext'). Pratically speaking, you organize the routes this way in routes/web.php. With a wise database management (and queries) you can easily mantain 2 separate websites within 1 Laravel application. This assuming you have control over your webserver, of course. If that's the case, i would suggest a refractoring. It's really worth the effort.

Related

How to create two separate sites login/registration with single database users table

I have two different websites one in Cakephp 2.6 Framework and another in Laravel 8x Framework.
I have two different databases but i want to uses my Cakephp site's database users table for login/registration for both sites, how to integrate this solution in my frameworks.
Thanks in advance!
According to my understanding: It doesn't related to frameworks, instead it is a matter of business logic and can be handled with two steps.
step 1 => Add a "system_code/website_code" column in the users table.
step 2 => Add additional check for system_code along with login credentials in your code base of both websites.

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/

Laravel 5 subdomain sites hosts as new project or not?

I have this issue where I cant decide what's for what and what is the best. Hope someone could provide me with some explanations to clear up my confusion.
So here it is, I have a site which is quite large. Currently running on Yii Framework which I am in the process of migrating it to L5 Framework. This website has several sub sites structure like below example:
1) www.example.com
2) www.example.com/{username}
3) explore.example.com
4) explore.example.com/{organization}
5) connect.example.com
6) coin.example.com
7) m.example.com
8) e3.example.com
So the current hosting method is using 1 project to host everything. Here comes the problem, should one of the sub sites were to be disabled for whatever reason, the whole website would need to be put to a stop, code to disable the site and the deploy the entire site again.
Back to L5 Framework, I noticed that I can do the same in laravel aslo to host everything in one project using the following routing methods in routes.php:
Route::group(['domain' => '{account}.myapp.com'], function()
{
Route::get('user/{id}', function($account, $id)
{
//
});
});
Again the same question rises, if there is a sub site to be disabled, I would need to code the disable site and redeploy the whole site again. So I was thinking if it is practical to host each sub sites in a new project as a module such that if any changes to that sub site, it will only affect that particular module while the others maintain running.
Additionally I would also like to ask, if I host it as a separate project, my website requires the user to login before they can navigate to any of the pages or application. So how do I tell the other modules where the user has been logged in and everything can be proceed as usual?
Finally of course if anyone have any other suggestions or approaches feel free to enlighten me too. My main motives are to achieve:
1) Maximum development flexibility
2) Fail tolerance
3) Sub sites can share the same login with the main website
(You are only require to login at the main page and you will be authorized
to use the rest of the web application)
Thank you.
I guess, the answer will be too late. Nevertheless, it might help someone else.
Today I faced a similar dilemma myself - should I use subsites or separate applications for public site and admin site of my application.
At first it seemed that I should have separate apps to avoid bringing down bith sites if I wish to upgrade just one of them. But I did not want to duplicate all the Laravel boilerplate code all over again in my repository.
Then it came to me that actually I can implement everything as subsites, but I can deploy the Laravel app to multiple subdomains. Thus there will be single app in the repository, but I'll have a different copy for each subdomain.
Drawback - the code of controllers, views (and some site specific models) will be duplicated for each deployed site. That's not an issue for a small site - just a bunch of unused files. But if I wanted a clean solution, I could implement some modular structure and bring in site-specific MVC stuff during deployment. That's another topic, I guess. There are some 3rd party solutions for modular Laravel apps. Of course, modular solution adds to the complexity and maintenance, therefore I have nothing against file duplication on server, if that's not an issue for you.
Regarding authentication - I haven't tried it with Laravel, but I have experience with implementing cookies for top level domain in pure PHP application. Essentially, you can configure your session cookie to be effective for all subdomains, and then users will have to log-in just once in any of your sites. Here seems to be a working solution for Laravel:
Persisting sessions across subdomains in Laravel 5
Just set the top level domain to .example.com and theoretically you should be good to go. For development purposes, I'd store this value in .env, though.

Login for two different users using laravel

I have made two login system. a) for Users and b) for Administrator.
But the problem is the app/config/auth.php in laravel has the default model=>'User' and
table=>'users' and I have two models and tables for different users.
How can I use the two different models and tables for login?
What you're doing is considered bad practice - you should take a look at role based permission systems or helpers. I have a few suggestions for you:
Sentry - Most popular, comes with permission system and roles
Entrust - Let's you add role based permissions
You should never repeat stuff for the same type of resource - that's like having a blog where you have a table for each category, it just doesn't really work and it's incredibly time consuming to keep up to date and in sync.
You should change your style right now, take the opportunity, it will save you time in the long run, believe me.

Resources