Skip to content
Advertisement

Laravel auth and “subdomains”

I’m using Laravel 5x and I’m trying to have the user login from (for example):

https://dev.example.com/example_authentication/public/login (this is one instance of laravel)

and then when I access:

https://dev.example.com/mysecondwebsite/public (this is another instance of laravel) I can just call:

JavaScript

and then get if its a user, admin, its name, etc.

What I’ve tried is to add both on the .env file of example_authentication and mysecondwebsite

JavaScript

but the session does not persist.

any idea on what’s happening?

UPDATE:

I’m using on the second laravel app

JavaScript

for some reason it’s generating its own session, for the record both instances have the same:

JavaScript

Advertisement

Answer

So I couldn’t integrate the first project session to the latter but found an alternative with the $_SESSION variable:

if you want to have this variable working for both projects you have to set session_start(); on public/index.php on both projects.

JavaScript

after that you can use the $_SESSION variable on every controller and this will show on any PHP web app you have on your server, I wanted to use the traditional way of laravel but had no luck and there isn’t much info about this requirement, so here’s the alternative.

You can use this variable like this inside any controller,view or middleware:

JavaScript

then on the controller, view or middleware you can just

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement