Reputation: 547
Our web site is built on top of a custom php mvc framework and we wanted to slowly convert each flow (for eg: signups) to Laravel.
So in essence, the existing code and the new code using laravel have to co-exist. But we hit a snag, where session information set by laravel is not availble to the other mvc and vice-versa because of their conventions.
For eg, the custom mvc uses the following.
$_SESSION['AUTH']='TRUE';
While Laravel uses something like this.
Session::put('AUTH', 'TRUE');
We tried to set $_SESSION['AUTH'] = 'TRUE' through laravel classes. But we are not able to access it when control is passed to the older MVC.
I know its complicated, and i should just wait to convert the entire code base to Laravel, and be done with it. But we are a small company with minimal resources. So we dont have the luxury to stop feature development and spend time re-writing using Laravel Exclusively.
So my question is this. How , if by any mechanism, can we achieve this?
Global variables?
Any other suggestions?
Upvotes: 6
Views: 2721
Reputation: 3297
I would recommend you to use Laravel's Auth
-Class here, listen to the auth.login
event and set your session flag by hand.
Event::listen('auth.login', function($user)
{
$_SESSION['AUTH']='TRUE';
});
It is the easiest way and you only have to delete the event listener when you completly migrated to Laravel.
I know this is a quick and dirty thing, but after full migration you don't want to use the $_SESSION
ever again to manage your authentication ;) so I think this should be a very good bridge between your new and old codebase.
Upvotes: 3
Reputation: 2560
Actually only by requiring bootstrap/autoload.php
and bootstrap/start.php
you will not be able to access the real Laravel session. Not even by calling Application::boot()
anymore.
I've created a Gist, that makes it possible to share Laravel's session and check authentication from external projects:
https://gist.github.com/frzsombor/ddd0e11f93885060ef35
Upvotes: 1
Reputation: 547
For example if you have the following folder stuctures
projectFolder/oldMVC
projectFolder/Laravel
in the oldMvC/main.php we included the following
require '../Laravel/bootstrap/autoload.php';
require_once '../Laravel/bootstrap/start.php';
After that we were able to access session and other config variables set in Laravel from the non Laravel MVC.
Upvotes: 1