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:

$user = Auth::user();

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

SESSION_DOMAIN='.example.com'

but the session does not persist.

any idea on what’s happening?

UPDATE:

I’m using on the second laravel app

$user = Auth::user();

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

 'cookie' => 'vanguard_session'
  the same APP_KEY
  the same SESSION_DRIVER

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.

<?php
session_start();

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:

$_SESSION["setyourvarname"]="your value";

then on the controller, view or middleware you can just

$myvariable = $_SESSION["myvarname"]
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement